Home>

$ruby ​​main.rb
Traceback (most recent call last):
2: from main.rb: 1: in

' 1: from /home/ec2-user/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
/home/ec2-user/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file-/ human (LoadError)
I get an error code like ↑.

(animal.rb file)
class Animal

attr_accessor: name,: age

def initialize (name, age)
self.name = name
self.age = age
end

def say
puts "# {self.name}. # {Self.age} years old."
end
end
animal = Animal.new ('Taro Tanaka', 25)
animal.say

(thinkable.rb file)
module Thinkable
def think
puts "I'm thinking about # {self.hobby}."
end
end

(Human.rb file)
require'./animal'
require'./thinkable'

class Human attr_accessor: hobby
def initialize (name, age, hobby)
self.name = name
self.age = age
self.hobby = hobby
end

include Thinkable
end

(Main.rb file)
require "/ human"

human = Human.new ("Taro Tanaka", 25, "Train")
human.say
suzuki.think

human = Human.new ("Jiro Suzuki", 30, "Baseball")
human.say
human.think

human = Human.new ("Hanako Sato", 20, "Movie")
human.say
human.think

  • Answer # 1

    require "/ human"

    Is strange.

    require'./animal'
    require'./thinkable'

    If there is no error inrequire "./human"Then?

  • Answer # 2

    require "/ human"

    require'./human'
    Or
    require_relative'human'

    I think.