/usr/lib/ruby/vendor_ruby/declarative/option.rb is in ruby-declarative-option 0.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | module Declarative
Callable = Module.new
def self.Option(value, options={})
Option.new.(value, options)
end
class Option
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
# All methods below are considered public API and are meant to be overridden.
def callable?(value, options)
value.is_a?(options[:callable] || Callable)
end
def lambda_for_proc(value, options)
return ->(context, *args) { context.instance_exec(*args, &value) } if options[:instance_exec]
value
end
def lambda_for_symbol(value, options)
->(context, *args){ context.send(value, *args) }
end
def lambda_for_callable(value, options)
value
end
def lambda_for_static(value, options)
->(*) { value }
end
end
end
|