Method: UnitMeasurements::Unit#with

Defined in:
lib/unit_measurements/unit.rb

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

Returns a new Unit instance with specified attributes.

Parameters:

  • name (String|Symbol) (defaults to: nil)

    The new name of the unit.

  • value (String|Numeric) (defaults to: nil)

    The new conversion value of the unit.

  • aliases (Set<String>) (defaults to: nil)

    New alternative names for the unit.

  • system (String|Symbol|NilClass) (defaults to: nil)

    The new system to which the unit belongs.

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

    The new unit group to which the unit belongs.

Returns:

  • (Unit)

    A new unit with specified parameters.

Author:

Since:

  • 1.0.0



86
87
88
89
90
91
92
93
94
# File 'lib/unit_measurements/unit.rb', line 86

def with(name: nil, value: nil, aliases: nil, system: nil, unit_group: nil)
  self.class.new(
    (name || self.name),
    value: (value || self.value),
    aliases: (aliases || self.aliases),
    system: (system || self.system),
    unit_group: (unit_group || self.unit_group)
  )
end