Class: Plucky::OptionsHash

Inherits:
Object
  • Object
show all
Defined in:
lib/plucky/options_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ OptionsHash

Returns a new instance of OptionsHash.



6
7
8
9
# File 'lib/plucky/options_hash.rb', line 6

def initialize(hash={})
  @source = {}
  hash.each { |key, value| self[key] = value }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



34
35
36
# File 'lib/plucky/options_hash.rb', line 34

def method_missing(method, *args, &block)
  @source.send(method, *args, &block)
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/plucky/options_hash.rb', line 4

def source
  @source
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/plucky/options_hash.rb', line 21

def ==(other)
  source == other.source
end

#[]=(key, value) ⇒ Object



16
17
18
19
# File 'lib/plucky/options_hash.rb', line 16

def []=(key, value)
  key = normalized_key(key)
  source[key] = normalized_value(key, value)
end

#fields?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/plucky/options_hash.rb', line 29

def fields?
  !self[:fields].nil?
end

#initialize_copy(source) ⇒ Object



11
12
13
14
# File 'lib/plucky/options_hash.rb', line 11

def initialize_copy(source)
  super
  @source = @source.dup
end

#to_hashObject



25
26
27
# File 'lib/plucky/options_hash.rb', line 25

def to_hash
  source
end