Class: Object

Inherits:
BasicObject
Defined in:
lib/lolita/ruby_ext/accessors.rb

Instance Method Summary collapse

Instance Method Details

#lolita_accessor(*methods) ⇒ Object

Works similar as attr_accessor only reader method is changed to allow to set value (used for Lolita blocks in different classes).

Example

class Klass
  lolita_accessor :my_method
end
k=Klass.new
k.my_method("it's me")
puts k.my_method #=> it's me


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lolita/ruby_ext/accessors.rb', line 11

def lolita_accessor *methods
  if [Class,Module].include?(self.class)
    methods.each do |method|
      class_eval "      def \#{method}(value=nil)\n        @\#{method}=value if value\n        @\#{method}\n      end\n\n      def \#{method}=(value)\n        @\#{method}=value\n      end\n      ACCESSORS\n    end\n  end\nend\n",__FILE__,__LINE__+1