Module: SmoothOperator::Delegation

Included in:
OpenStruct
Defined in:
lib/smooth_operator/delegation.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/smooth_operator/delegation.rb', line 8

def method_missing(method, *args, &block)
  method_name = method.to_s

  if !! ((method.to_s) =~ /=$/) #setter method
    internal_data_push(method_name[0..-2], args.first)
  elsif !self.class.strict_behaviour || known_attribute?(method_name)
    internal_data_get(method_name)
  else
    super
  end
end

Class Method Details

.included(base) ⇒ Object



20
21
22
# File 'lib/smooth_operator/delegation.rb', line 20

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/smooth_operator/delegation.rb', line 4

def respond_to?(method, include_private = false)
  known_attribute?(method) ? true : super
end