$ruby main.rb
Traceback (most recent call last):
2: from main.rb: 1: in
require'
/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
-
Answer # 2
require "/ human"
require'./human'
Or
require_relative'human'
I think.
Related articles
- ruby - i want to resolve an error when installing gem byebug
- ruby on rails - i get an error with rails db: create
- ruby on rails 6 - about rails routing error no route matches [get] "/"
- ruby - http error 500 error occurred in aws deployment, but the cause cannot be determined
- ruby - validation error when saving intermediate table
- ruby - i got "mysql2 :: error :: connectionerror: plugin caching_sha2_password could not be loaded "
- ruby on rails uninitialized constant error
- ruby - i get an error with a single test code for a model
- ruby on rails - error when implementing rails6 follow function
- ruby - i entered secret_key_base, but http error 500 cannot be resolved
- ruby on rails 6 - when i press new user registration, i get an error of no route matches [get] "/ users"
- ruby on rails - i get an error without being created
- ruby - i got a routing error when i sent a comment
- ruby on rails - nomethoderror in itemscontroller # new error
- ruby on rails - i get an error in a program that changes over time
- ruby on rails - i don't understand the content of the error
- ruby - routing error no route matches [post] i want to resolve "/ items/new"
- ruby on rails - syntax error cannot be resolved
- ruby - [rspec] error in "dependent: destoy" test: how to resolve "validation failed"
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
Is strange.
If there is no error in
require "./human"
Then?