Method: Hackeroo::Base.attr_reader
- Defined in:
- lib/hackeroo/base.rb
.attr_reader(*attrs) ⇒ Object
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/hackeroo/base.rb', line 8 def self.attr_reader(*attrs) mod = Module.new do attrs.each do |attribute| define_method attribute do @attrs[attribute.to_sym] end define_method "#{attribute}?" do !!@attrs[attribute.to_sym] end end end const_set(:Attributes, mod) include mod end |