Sha256: 287dcec26867c8d395304d8f740cb051630cdcd4e316b10e0afa8d99872a2ef4

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

# license is MIT

$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'volute'

#
# our class

class Equation
  include Volute

  attr_accessor :km, :h, :kph

  def initialize
    @km = 1.0
    @h = 1.0
    @kph = 1.0
  end

  def inspect

    "#{@km} km, #{@h} h, #{@kph} kph"
  end
end

#
# a volute per attribute

volute Equation do

  # object.vset(:state, x)
  #   is equivalent to
  # object.instance_variable_set(:@state, x)

  volute :km do
    object.vset(:h, value / object.kph)
  end
  volute :h do
    object.vset(:kph, object.km / value)
  end
  volute :kph do
    object.vset(:h, object.km / value)
  end
end

#
# trying

e = Equation.new
p e # => 1.0 km, 1.0 h, 1.0 kph

e.kph = 10.0
p e # => 1.0 km, 0.1 h, 10.0 kph

e.km = 5.0
p e # => 5.0 km, 0.5 h, 10.0 kph

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
volute-0.1.1 examples/equation.rb