Class: Surrogate::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/surrogate/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, default_proc) ⇒ Options

Returns a new instance of Options.



5
6
7
# File 'lib/surrogate/options.rb', line 5

def initialize(options, default_proc)
  self.options, self.default_proc = options, default_proc
end

Instance Attribute Details

#default_procObject

Returns the value of attribute default_proc.



3
4
5
# File 'lib/surrogate/options.rb', line 3

def default_proc
  @default_proc
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/surrogate/options.rb', line 3

def options
  @options
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/surrogate/options.rb', line 13

def [](key)
  options[key]
end

#default(instance, args, &no_default) ⇒ Object



21
22
23
24
25
# File 'lib/surrogate/options.rb', line 21

def default(instance, args, &no_default)
  return options[:default] if options.has_key? :default
  return instance.instance_exec(*args, &default_proc) if default_proc
  no_default.call
end

#has?(name) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/surrogate/options.rb', line 9

def has?(name)
  options.has_key? name
end

#to_hashObject



17
18
19
# File 'lib/surrogate/options.rb', line 17

def to_hash
  options
end