Skip to content

Instantly share code, notes, and snippets.

@arr-ee
Created August 15, 2012 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arr-ee/3357278 to your computer and use it in GitHub Desktop.
Save arr-ee/3357278 to your computer and use it in GitHub Desktop.
Unmaintainable
1.9.3p125 :001 > User
=> User(id: integer, name: string, created_at: datetime, updated_at: datetime)
1.9.3p125 :002 > User.create name: 'test'
=> #<User id: 1, name: "test", created_at: "2012-08-15 06:58:45", updated_at: "2012-08-15 06:58:45">
1.9.3p125 :003 > u = User.first
=> #<User id: 1, name: "test", created_at: "2012-08-15 06:58:45", updated_at: "2012-08-15 06:58:45">
1.9.3p125 :004 > u.last_name
NoMethodError: undefined method `last_name' for #<User:0x007fa9a59a9d08>
1.9.3p125 :005 > u.last_name = 'failed'
NoMethodError: undefined method `last_name=' for #<User:0x007fa9a59a9d08>
1.9.3p125 :006 > uu = User.find_by_sql %[SELECT *, 'passed' AS last_name FROM users;].first
=> #<User id: 1, name: "test", created_at: "2012-08-15 06:58:45", updated_at: "2012-08-15 06:58:45">
1.9.3p125 :007 > uu.last_name
=> "passed"
1.9.3p125 :008 > uu.last_name = 'passed again'
=> "passed again"
1.9.3p125 :009 > uu.last_name
=> "passed again"
1.9.3p125 :010 > uu.save
=> true
1.9.3p125 :011 > uu.reload.last_name
=> "passed again"
1.9.3p125 :012 > uu = User.first
=> #<User id: 1, name: "test", created_at: "2012-08-15 06:58:45", updated_at: "2012-08-15 07:00:59">
1.9.3p125 :013 > uu.last_name
NoMethodError: undefined method `last_name' for #<User:0x007fa9a5dd3fa0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment