- In your own words, what is the purpose of a method?
- The purpose of a method is to modify an instance of an attribute of a class
- Create a method named
hello
that will print"Sam I am"
.
def hello
puts "Sam I am"
end
- Create a method named
hello_someone
that takes an argument ofname
and prints"#{name} I am"
.
def hello_someone(name)
puts "#{name} I am"
end
- How would you call or execute the method that you created above?
- You would type
hello_someone(name)
on the command line - I believe you could call it with
.hello_someone
.
- What questions do you have about methods in Ruby?
- Some methods are universal to ruby. Why do we need to think of methods as a way to change an attribute? Couldn't we just think of a method as a way to accomplish a task with our code?