Class: SpaceAge

Inherits:
Object
  • Object
show all
Defined in:
lib/hack01/space_age.rb

Overview

Definition of class SpaceAge for Exercism

Constant Summary collapse

EARTH_YEAR_IN_SECONDS =
31_557_600
PLANETS =
{
  Earth: 1,
  Mercury: 0.2408467,
  Venus: 0.61519726,
  Mars: 1.8808158,
  Jupiter: 11.862615,
  Saturn: 29.447498,
  Uranus: 84.016846,
  Neptune: 164.79132
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ SpaceAge

Returns a new instance of SpaceAge.



16
17
18
# File 'lib/hack01/space_age.rb', line 16

def initialize(seconds)
  @seconds = seconds
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/hack01/space_age.rb', line 26

def method_missing(name, *args, &block)
  # first time using method_missing
  # super basically checks if the method exists in the class's ancestor
  # (if any)
  super
  raise "'#{name}' is not a method of the class #{self.class}"
end

Instance Method Details

#respond_to_missing?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/hack01/space_age.rb', line 34

def respond_to_missing?(*)
  p 'not sure what to do here but'
  p "rubocop recommends a 'respond_to_missing?' method"
end