Class: Rlyeh::Environment

Inherits:
Hash
  • Object
show all
Defined in:
lib/rlyeh/environment.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
# File 'lib/rlyeh/environment.rb', line 15

def method_missing(method_id, *args, &block)
  method_name = method_id.to_s
  return self[$1] = args.first if method_name =~ /^(.+)=$/
  return self.has_key? $1 if method_name =~ /^has_(.+)\?$/
  return self[method_name] if self.key? method_name
  super
end

Instance Method Details

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

Returns:

  • (Boolean)


3
4
5
# File 'lib/rlyeh/environment.rb', line 3

def respond_to?(method_id, include_private = false)
  super || respond_to_missing?(method_id, include_private)
end

#respond_to_missing?(method_id, include_private) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'lib/rlyeh/environment.rb', line 7

def respond_to_missing?(method_id, include_private)
  method_name = method_id.to_s
  return true if method_name =~ /^(.+)=$/
  return true if method_name =~ /^has_(.+)\?$/
  return true if self.key? method_name
  super
end