Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. class Article < ActiveRecord::Base
  2. STATES = %w(review published)
  3. validates :state, :inclusion => {:in => STATES}
  4.  
  5. STATES.each do |state|
  6. define_method "#{state}?" do
  7. self.state == state
  8. end
  9. end
  10.  
  11. class << self
  12. STATES.each do |state|
  13. define_method "#{state}" do
  14. state
  15. end
  16. end
  17. end
  18. end
  19.  
  20. @article.state = State.find_by_name("published")
  21.  
  22. @article.state = State.published
  23.  
  24. @article.state = Article.published
  25.  
  26. class MyClass
  27. class << self
  28. def my_method
  29. puts 'this is a method'
  30. end
  31. end
  32. end
  33.  
  34. class MyClass
  35. def self.my_method
  36. puts 'this is a method'
  37. end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement