Class: Muack::Satisfying

Inherits:
Struct
  • Object
show all
Defined in:
lib/muack/satisfying.rb

Direct Known Subclasses

Anything, Including, IsA, Matching, RespondingTo, Conj, Disj, Where, Within

Defined Under Namespace

Classes: Conj, Disj

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil, &block) ⇒ Satisfying

Returns a new instance of Satisfying.



6
7
8
# File 'lib/muack/satisfying.rb', line 6

def initialize args=nil, &block
  super(args, block)
end

Instance Attribute Details

#api_argsObject

Returns the value of attribute api_args

Returns:

  • (Object)

    the current value of api_args



5
6
7
# File 'lib/muack/satisfying.rb', line 5

def api_args
  @api_args
end

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



5
6
7
# File 'lib/muack/satisfying.rb', line 5

def block
  @block
end

Instance Method Details

#&(rhs) ⇒ Object



15
# File 'lib/muack/satisfying.rb', line 15

def & rhs; Satisfying::Conj.new(self, rhs); end

#api_nameObject



48
49
50
51
# File 'lib/muack/satisfying.rb', line 48

def api_name
  (self.class.name || 'Unknown')[/(::)*(\w+)$/, 2].
    gsub(/([A-Z][a-z]*)+?(?=[A-Z][a-z]*)/, '\\1_').downcase
end

#match(actual_arg) ⇒ Object



10
11
12
# File 'lib/muack/satisfying.rb', line 10

def match actual_arg
  !!block.call(actual_arg)
end

#to_sObject Also known as: inspect



43
44
45
# File 'lib/muack/satisfying.rb', line 43

def to_s
  "Muack::API.#{api_name}(#{api_args.map(&:inspect).join(', ')})"
end

#|(rhs) ⇒ Object



14
# File 'lib/muack/satisfying.rb', line 14

def | rhs; Satisfying::Disj.new(self, rhs); end