Module: InspectorGadget::StickyAttributes

Included in:
ModulePreferences, UserPreference
Defined in:
lib/inspectorgadget/sticky_attributes.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/inspectorgadget/sticky_attributes.rb', line 4

def method_missing(method_name, *args)
  attr_name = method_name.to_s.split(/=|\?/).first.to_sym
  unless args.empty?
    attr_value = args.first
    eval %(class << self
             def #{attr_name}(*attr_args)
               @#{attr_name} = attr_args.first unless attr_args.empty?
               @#{attr_name}
             end
             attr_writer :#{attr_name}
             alias_method :#{attr_name}?, :#{attr_name}
           end)
    sticky_attributes[attr_name] = attr_value
  end
  
  respond_to?(method_name) ? send(method_name, *args) : super
end

Instance Method Details

#sticky_attributesObject



22
23
24
# File 'lib/inspectorgadget/sticky_attributes.rb', line 22

def sticky_attributes
  @sticky_attributes ||= {}
end