Module: RAWG::Utils::ClassMethods
- Defined in:
- lib/rawg/utils.rb
Instance Method Summary collapse
Instance Method Details
#lazy_attr_accessor(*attrs, init:) ⇒ Object
10 11 12 13 |
# File 'lib/rawg/utils.rb', line 10 def lazy_attr_accessor(*attrs, init:) attr_writer(*attrs) lazy_attr_reader(*attrs, init: init) end |
#lazy_attr_reader(*attrs, init:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rawg/utils.rb', line 15 def lazy_attr_reader(*attrs, init:) attrs.each do |attr| define_method(attr) do instance_variable_get("@#{attr}") || begin init.call(attr) instance_variable_get("@#{attr}") end end end end |