Class: Object

Inherits:
BasicObject
Defined in:
lib/redmine_extensions/core_ext/object.rb

Instance Method Summary collapse

Instance Method Details

#nested_send(symbol) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/redmine_extensions/core_ext/object.rb', line 3

def nested_send(symbol)
  return __send__(symbol) if respond_to?(symbol)
  obj = nil
  symbol.to_s.split('.').each do |part|
    nested_symbol = part.to_sym
    if obj
      break unless obj.respond_to?(nested_symbol)
      obj = obj.__send__(nested_symbol)
    else
      break unless respond_to?(nested_symbol)
      obj = __send__(nested_symbol)
    end
  end
  obj
end