Skip to content

Instantly share code, notes, and snippets.

@jdunphy
Created March 1, 2010 20:15
Show Gist options
  • Select an option

  • Save jdunphy/318762 to your computer and use it in GitHub Desktop.

Select an option

Save jdunphy/318762 to your computer and use it in GitHub Desktop.
def id_is(attribute)
 (file, line) = caller.first.split(':')
class_eval(<<-EOS, file, line.to_i)
def #{attribute}=(value)
#{attribute} = value.to_i
end
attr_reader #{attribute.inspect}
alias :id #{attribute.inspect}
alias :id= #{"#{attribute}=".to_sym.inspect}
EOS
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment