Class: ActiveSupport::Duration::Scalar
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| 
         Class Chain: 
        
          self,
           
      ::Numeric
         | 
    |
| 
         Instance Chain: 
        
          self,
           
      ::Numeric
         | 
    |
| Inherits: | Numeric | 
| Defined in: | activesupport/lib/active_support/duration.rb | 
Constant Summary
Class Method Summary
- .new(value) ⇒ Scalar constructor
 
Instance Attribute Summary
- #value readonly
 - #variable? ⇒ Boolean readonly
 
::Numeric - Inherited
| #html_safe?, | |
| #blank? | No number is blank:  | 
    
| #present? | |
Instance Method Summary
- #%(other)
 - #*(other)
 - #+(other)
 - #-(other)
 - #-@
 - #/(other)
 - #<=>(other)
 - #coerce(other)
 - #to_f
 - #to_i
 - #to_s
 - #calculate(op, other) private
 - #raise_type_error(other) private
 
::Numeric - Inherited
| #byte | Alias for Numeric#bytes.  | 
    
| #bytes | Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes.  | 
    
| #day | Alias for Numeric#days.  | 
    
| #days | Returns a   | 
    
| #exabyte | Alias for Numeric#exabytes.  | 
    
| #exabytes | Returns the number of bytes equivalent to the exabytes provided.  | 
    
| #fortnight | Alias for Numeric#fortnights.  | 
    
| #fortnights | Returns a   | 
    
| #gigabyte | Alias for Numeric#gigabytes.  | 
    
| #gigabytes | Returns the number of bytes equivalent to the gigabytes provided.  | 
    
| #hour | Alias for Numeric#hours.  | 
    
| #hours | Returns a   | 
    
| #in_milliseconds | Returns the number of milliseconds equivalent to the seconds provided.  | 
    
| #kilobyte | Alias for Numeric#kilobytes.  | 
    
| #kilobytes | Returns the number of bytes equivalent to the kilobytes provided.  | 
    
| #megabyte | Alias for Numeric#megabytes.  | 
    
| #megabytes | Returns the number of bytes equivalent to the megabytes provided.  | 
    
| #minute | Alias for Numeric#minutes.  | 
    
| #minutes | Returns a   | 
    
| #petabyte | Alias for Numeric#petabytes.  | 
    
| #petabytes | Returns the number of bytes equivalent to the petabytes provided.  | 
    
| #second | Alias for Numeric#seconds.  | 
    
| #seconds | Returns a   | 
    
| #terabyte | Alias for Numeric#terabytes.  | 
    
| #terabytes | Returns the number of bytes equivalent to the terabytes provided.  | 
    
| #week | Alias for Numeric#weeks.  | 
    
| #weeks | Returns a   | 
    
| #zettabyte | Alias for Numeric#zettabytes.  | 
    
| #zettabytes | Returns the number of bytes equivalent to the zettabytes provided.  | 
    
| #as_json | |
Constructor Details
    .new(value)  ⇒ Scalar 
  
Instance Attribute Details
#value (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/duration.rb', line 16
attr_reader :value
    #variable?  ⇒ Boolean  (readonly)
  
  [ GitHub ]
# File 'activesupport/lib/active_support/duration.rb', line 93
def variable? # :nodoc: false end
Instance Method Details
#%(other)
[ GitHub ]#*(other)
[ GitHub ]#+(other)
[ GitHub ]# File 'activesupport/lib/active_support/duration.rb', line 41
def +(other) if Duration === other seconds = value + other._parts.fetch(:seconds, 0) new_parts = other._parts.merge(seconds: seconds) new_value = value + other.value Duration.new(new_value, new_parts, other.variable?) else calculate(:+, other) end end
#-(other)
[ GitHub ]# File 'activesupport/lib/active_support/duration.rb', line 53
def -(other) if Duration === other seconds = value - other._parts.fetch(:seconds, 0) new_parts = other._parts.transform_values(&:-@) new_parts = new_parts.merge(seconds: seconds) new_value = value - other.value Duration.new(new_value, new_parts, other.variable?) else calculate(:-, other) end end
#-@
[ GitHub ]#/(other)
[ GitHub ]#<=>(other)
[ GitHub ]#calculate(op, other) (private)
[ GitHub ]#coerce(other)
[ GitHub ]# File 'activesupport/lib/active_support/duration.rb', line 23
def coerce(other) [Scalar.new(other), self] end
#raise_type_error(other) (private)
# File 'activesupport/lib/active_support/duration.rb', line 108
def raise_type_error(other) raise TypeError, "no implicit conversion of #{other.class} into #{self.class}" end