Condy

# rubocop:disable all

class Condy
  
  def initialize(&bl)
    @procs = []
    @cur = {}
    instance_exec(&bl) if bl
  end

  def (&bl) = ( @procs << bl )
  def ¤(name, &bl) = ( @cur[name] = bl )
  
  def check(*args)
    [].tap {|arr| args.each_with_index {|val, idx|
      arr << @procs[idx].(val) }
    }.map(&->{it ? '1':'0'}).join
  end

end

name = 'Olle'
age = 32
logged_in = false
color = :ruby_red

# test 1

c = Condy.new {
   {/^\w+$/.match?(it)}
   {Integer === it && it.between?(0, 100)}
   {it}
   {%i(red white blue).include?(it)}
}


p c.check name, age, logged_in, color #           => "1100"
p c.check(name, age, logged_in, color).to_i(2) #  => 12

p case c.check name, age, logged_in, color
  when /^11../ then 'name and age OK'
  else 'misery and fail'
end
# => "name and age OK"

p '-' * 80



# test 2 : testing curry
c = Condy.new {
  ¤(:divby) {|d,i| i % d == 0 }
  [3,5].each {|n|  @cur[:divby].curry[n].(it) }
}

[*1..20].each {
  p [it, :buzz, :fizz, :fizzbuzz][c.check(it, it).to_i(2)]
}

=begin OUTPUT
1
2
:fizz
4
:buzz
:fizz
7
8
:fizz
:buzz
11
:fizz
13
14
:fizzbuzz
16
17
:fizz
19
:buzz
=end