class Declarative::Option
Constants
- VERSION
Public Instance Methods
call(value, options={})
click to toggle source
# File lib/declarative/option.rb, line 9 def call(value, options={}) return lambda_for_proc(value, options) if value.is_a?(Proc) return lambda_for_symbol(value, options) if value.is_a?(Symbol) return lambda_for_callable(value, options) if callable?(value, options) lambda_for_static(value, options) end
Private Instance Methods
callable?(value, options)
click to toggle source
All methods below are considered public API and are meant to be overridden.
# File lib/declarative/option.rb, line 19 def callable?(value, options) value.is_a?(options[:callable] || Callable) end
lambda_for_callable(value, options)
click to toggle source
# File lib/declarative/option.rb, line 32 def lambda_for_callable(value, options) value end
lambda_for_proc(value, options)
click to toggle source
# File lib/declarative/option.rb, line 23 def lambda_for_proc(value, options) return ->(context, *args) { context.instance_exec(*args, &value) } if options[:instance_exec] value end
lambda_for_static(value, options)
click to toggle source
# File lib/declarative/option.rb, line 36 def lambda_for_static(value, options) ->(*) { value } end
lambda_for_symbol(value, options)
click to toggle source
# File lib/declarative/option.rb, line 28 def lambda_for_symbol(value, options) ->(context, *args){ context.send(value, *args) } end