Method: UnitMeasurements::Unit#initialize

Defined in:
lib/unit_measurements/unit.rb

#initialize(name, value:, aliases:, system:, unit_group: nil) ⇒ Unit

Initializes a new Unit instance.

Parameters:

  • name (String|Symbol)

    The name of the unit.

  • value (String|Numeric)

    The conversion value of the unit.

  • aliases (Array<String|Symbol>)

    Alternative names for the unit.

  • system (String|Symbol|NilClass)

    The system to which the unit belongs.

  • unit_group (UnitGroup|NilClass) (defaults to: nil)

    The unit group to which the unit belongs.

Author:

Since:

  • 1.0.0



66
67
68
69
70
71
72
# File 'lib/unit_measurements/unit.rb', line 66

def initialize(name, value:, aliases:, system:, unit_group: nil)
  @name = name.to_s.freeze
  @value = value
  @aliases = Set.new(aliases.map(&:to_s).sort.map(&:freeze)).freeze
  @system = system.to_s.freeze
  @unit_group = unit_group
end