Class: OpenObject

Inherits:
Hash show all
Defined in:
lib/buildr/core/util.rb

Instance Method Summary collapse

Methods inherited from Hash

#except, from_java_properties, #only, #to_java_properties

Constructor Details

#initialize(source = nil, &block) ⇒ OpenObject

Returns a new instance of OpenObject.



193
194
195
196
# File 'lib/buildr/core/util.rb', line 193

def initialize(source=nil, &block)
  @hash = Hash.new(&block)
  @hash.update(source) if source
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



214
215
216
217
218
219
220
# File 'lib/buildr/core/util.rb', line 214

def method_missing(symbol, *args)
  if symbol.to_s =~ /=$/
    self[symbol.to_s[0..-2].to_sym] = args.first
  else
    self[symbol]
  end
end

Instance Method Details

#[](key) ⇒ Object



198
199
200
# File 'lib/buildr/core/util.rb', line 198

def [](key)
  @hash[key]
end

#[]=(key, value) ⇒ Object



202
203
204
# File 'lib/buildr/core/util.rb', line 202

def []=(key, value)
  @hash[key] = value
end

#delete(key) ⇒ Object



206
207
208
# File 'lib/buildr/core/util.rb', line 206

def delete(key)
  @hash.delete(key)
end

#to_hashObject



210
211
212
# File 'lib/buildr/core/util.rb', line 210

def to_hash
  @hash.clone
end