Module: SmoothOperator::Delegation

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/smooth_operator/delegation.rb', line 9

def method_missing(method, *args, &block)
  method_type, method_name = *parse_method(method)

  result = case method_type
  when :was
    get_internal_data(method_name, :was)
  when :changed
    get_internal_data(method_name, :changed?)
  when :setter
    return push_to_internal_data(method_name, args.first)
  else
    return get_internal_data(method_name) if !self.class.strict_behaviour || respond_to?(method_name)
  end

  result.nil? ? super : result
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to?(method)
  known_attributes.include?(method.to_s) ? true : super
end