Class: Plucky::OptionsHash

Inherits:
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)



46
47
48
# File 'lib/plucky/options_hash.rb', line 46

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



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

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

#[]=(key, value) ⇒ Object



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

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

#fields?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/plucky/options_hash.rb', line 32

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

#initialize_copy(source) ⇒ Object



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

def initialize_copy(source)
  super
  @source = @source.dup
  each do |key, value|
    self[key] = value.clone if value.duplicable?
  end
end

#merge(other) ⇒ Object



36
37
38
# File 'lib/plucky/options_hash.rb', line 36

def merge(other)
  self.class.new(to_hash.merge(other.to_hash))
end

#merge!(other) ⇒ Object



40
41
42
43
# File 'lib/plucky/options_hash.rb', line 40

def merge!(other)
  other.to_hash.each { |key, value| self[key] = value }
  self
end

#to_hashObject



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

def to_hash
  source
end