VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/lib/gems/2.5.0/gems/tins-1.28.0/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/lib/gems/2.5.0/gems/tins-1.28.0/examples/recipe2.rb
#!/usr/bin/env ruby

require 'tins/xt'
$:.unshift 'examples'
require 'recipe_common'

class Cup < Unit; end
class Teaspoon < Unit; end
class Tablespoon < Unit; end

class Flour < Ingredient; end
class Bakingpowder < Ingredient; end
class Salt < Ingredient; end
class Egg < Ingredient; end
class Milk < Ingredient; end
class Butter < Ingredient; end

class Recipe < Tins::BlankSlate.with(:respond_to?, :instance_exec, :inspect, /^deflect/)
  include Tins::Deflect

  def initialize(&block)
    @ingredients = []
    deflector = Deflector.new do |number, id, name|
      if unit = Unit.unit(name, number)
        unit
      else
        ingredient = Ingredient.ingredient(name, number)
        @ingredients << ingredient
      end
    end
    deflect_start(Numeric, :method_missing, deflector)
    deflector2 = Deflector.new do |unit, id, name|
      ingredient = Ingredient.ingredient(name, unit)
      @ingredients << ingredient
    end
    deflect_start(Unit, :method_missing, deflector2)
    instance_exec(&block)
  ensure
    deflect_stop(Numeric, :method_missing) if deflect?(Numeric, :method_missing)
    deflect_stop(Unit, :method_missing) if deflect?(Unit, :method_missing)
  end

  attr_reader :ingredients

  def to_a
    @ingredients
  end
  alias to_ary to_a

  def to_s
    to_a * "\n"
  end
end

class RecipeInterpreter
  def recipe(&block)
    Recipe.new(&block)
  end
end

recipe_source = <<EOT
pancakes = recipe do
  2.cups.         flour
  2.5.teaspoons.  baking_powder
  0.5.teaspoon.   salt
  1.              egg
  1.5.cups.       milk
  2.tablespoons.  butter
end
EOT

pancakes = RecipeInterpreter.new.interpret(recipe_source)
puts pancakes

puts

def recipe(&block)
  Recipe.new(&block)
end

pancakes = eval recipe_source
puts pancakes

VaKeR 2022