Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Article < ActiveRecord::Base
- STATES = %w(review published)
- validates :state, :inclusion => {:in => STATES}
- STATES.each do |state|
- define_method "#{state}?" do
- self.state == state
- end
- end
- class << self
- STATES.each do |state|
- define_method "#{state}" do
- state
- end
- end
- end
- end
- @article.state = State.find_by_name("published")
- @article.state = State.published
- @article.state = Article.published
- class MyClass
- class << self
- def my_method
- puts 'this is a method'
- end
- end
- end
- class MyClass
- def self.my_method
- puts 'this is a method'
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement