File: option.rb

package info (click to toggle)
ruby-uber 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 216 kB
  • sloc: ruby: 466; makefile: 4
file content (16 lines) | stat: -rw-r--r-- 494 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
require "uber/callable"

module Uber
  class Option
    def self.[](value, options={}) # TODO: instance_exec: true
      if value.is_a?(Proc)
        return ->(context, *args) { context.instance_exec(*args, &value) } if options[:instance_exec]
        return value
      end

      return value                                            if value.is_a?(Uber::Callable)
      return ->(context, *args){ context.send(value, *args) } if value.is_a?(Symbol)
      ->(*) { value }
    end
  end
end