This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p((_=[gets.split,[],"+-**/"])[0].map{|__|__=~/[0-9\.]+/?_[1]<<__.to_f : _[2][__]?_[1]<<_[1].pop.send(__,_[1].pop):0}[0][0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A | |
| class << self | |
| private | |
| def foo | |
| puts "bar" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| alias_method :inspect, :to_s | |
| def initialize(name, email) | |
| @name = name | |
| @email = email | |
| end | |
| def to_s | |
| "#{@name} <#{@email}>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Assertive | |
| FailedConstraint = Class.new(StandardError) | |
| class << self | |
| attr_accessor :enabled | |
| end | |
| def constraints | |
| @constraints ||= [] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BoundedStack | |
| OverflowError = Class.new(StandardError) | |
| invariant { data.size <= limit } | |
| def initialize(limit) | |
| self.data = [] | |
| self.limit = limit | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Person | |
| attr_accessor :email, :first_name, :last_name | |
| end | |
| class Employee | |
| include Person | |
| attr_accessor :role | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module A | |
| def a | |
| end | |
| end | |
| module B | |
| def b | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| articles = BrokenRecord::Table.new(:name => "articles", | |
| :db => BrokenRecord.database) | |
| articles.insert(:body => "Hey joe", :title => "blah") | |
| articles.delete(:id => 10) | |
| articles.columns | |
| (return array of hashes) | |
| articles.all | |
| (select * from articles), returns an array of hashes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def update(id, params) | |
| # FIXME: This is not secure | |
| sql = params.map { |k,v| "#{k} = #{v.inspect}" }.join(", ") | |
| # BrokenRecord.database is just an instance of Sqlite::Database | |
| BrokenRecord.database.execute %{ | |
| update #{@table_name} | |
| set #{sql} | |
| where id = #{id} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "minitest/autorun" | |
| require "delegate" | |
| require "sqlite3" | |
| describe "Mapping fields in results" do | |
| before do | |
| BrokenRecord.database = SQLite3::Database.new(":memory:") | |
| BrokenRecord.database.execute %{ |