Method: UnitMeasurements::UnitGroupBuilder#system

Defined in:
lib/unit_measurements/unit_group_builder.rb

#system(system_name, &block) ⇒ Object

Defines the unit system within the unit group and evaluates the provided block in the context of the builder.

This method is used to group multiple units within the certain unit system, viz., metric, imperial, etc.

Examples:

Defining an imperial system with inches and feet:

system :imperial do
  unit "in", value: "25.4 mm", aliases: ['"', "inch", "inches"]
  unit "ft", value: "12 in", aliases: ["'", "foot", "feet"]
end

Parameters:

  • system_name (String|Symbol)

    The name of the unit system in which the units are to be grouped.

  • block

    A block of code to be executed in the context of the builder.

Since:

  • 4.0.0



106
107
108
109
110
111
# File 'lib/unit_measurements/unit_group_builder.rb', line 106

def system(system_name, &block)
  @system = system_name
  instance_eval(&block) if block_given?
ensure
  @system = nil
end