Class: Alf::Predicate::ToProc

Inherits:
Object
  • Object
show all
Defined in:
lib/alf-predicate/alf/predicate/processors/to_proc.rb

Defined Under Namespace

Modules: ProcMethods

Class Method Summary collapse

Class Method Details

.call(expr, options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/alf-predicate/alf/predicate/processors/to_proc.rb', line 14

def self.call(expr, options = {})
  code = "lambda{ #{to_ruby_code(expr, options)} }"
  proc = Kernel.eval(code)
  proc.extend(ProcMethods)
  proc.source_code = code
  proc
end

.to_ruby_code(expr, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/alf-predicate/alf/predicate/processors/to_proc.rb', line 24

def self.to_ruby_code(expr, options = {})
  case expr
  when String then expr
  when Expr   then ToRubyCode.call(expr, options)
  else
    raise ArgumentError, "Unable to convert `#{expr}` to ruby source code"
  end
end