Created
June 29, 2012 08:36
-
-
Save gabriel-dehan/3016681 to your computer and use it in GitHub Desktop.
OwningRails#Question
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
# So we have something like this : | |
class User | |
class << self | |
def find_by_sql(sql) | |
rows = @@connector.execute(sql) | |
# => [[1, 'Marc']] | |
rows.map do |row| | |
attributes = match_columns_to_values(row) | |
# match_columns_to_values returns a Hash if I recall | |
new attributes | |
end # => <#Enumerable:[[1, 'Marc']]:map> | |
end | |
end | |
end | |
class TestClass | |
class << self | |
def test_method | |
self.class # => Class | |
[[1,'Marc']].map do | |
self.class # => Class | |
new({}) # => #<User:0x007fc413906b20> | |
new({ id: 1,name: 'Marc' }) # => ArgumentError : wrong number of arguments ( 1 of 0 ) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment