Skip to content

Instantly share code, notes, and snippets.

@gabriel-dehan
Created June 29, 2012 08:36
Show Gist options
  • Save gabriel-dehan/3016681 to your computer and use it in GitHub Desktop.
Save gabriel-dehan/3016681 to your computer and use it in GitHub Desktop.
OwningRails#Question
# 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