Class: Clive::Argument::AlwaysTrue

Inherits:
Object
  • Object
show all
Defined in:
lib/clive/argument.rb

Overview

Creates an object which will respond with true to all call to the method(s) given.

Examples:

eg = AlwaysTrue.for(:a, :b, :c)
eg.a          #=> true
eg.b(1,2,3)   #=> true
eg.c { 1 }    #=> true
eg.d          #=> NoMethodError

Class Method Summary collapse

Class Method Details

.for(*syms) ⇒ Object

Parameters:

  • syms (Symbol)

    Methods which should return true


20
21
22
23
24
25
26
27
# File 'lib/clive/argument.rb', line 20

def self.for(*syms)
  c = Class.new
  syms.each do |sym|
    c.send(:define_method, sym) {|*a| true }
  end
  c.send(:define_method, :inspect) { "#<AlwaysTrue #{syms.map {|i| ":#{i}" }.join(', ') }>" }
  c.new
end