Class: Predicate::Dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/predicate/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(var = nil, allow_currying = true) ⇒ Dsl

Returns a new instance of Dsl.



4
5
6
7
# File 'lib/predicate/dsl.rb', line 4

def initialize(var = nil, allow_currying = true)
  @var = var || ::Predicate.var(".", :dig)
  @allow_currying = allow_currying
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(n, *args, &bl) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/predicate/dsl.rb', line 96

def method_missing(n, *args, &bl)
  snaked, to_negate = missing_method_pair(n)
  if snaked == n.to_s && !to_negate
    super
  elsif self.respond_to?(snaked)
    got = __send__(snaked.to_sym, *args, &bl)
    to_negate ? !got : got
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(n, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
112
# File 'lib/predicate/dsl.rb', line 108

def respond_to_missing?(n, include_private = false)
  snaked, to_negate = missing_method_pair(n)
  return super if snaked == n.to_s
  self.respond_to?(snaked)
end