!Mac OS X-10.15.7!ruby-2.7.1p83
Ruby variables do not require type declarations (int, char, etc. for C).
For example, assigning to a variable
name = 'Rudy'
You can do it with.
Substitute the argument ARGV [0] for the argument name
> ruby name_variable.rb Rudy
Hello Rudy.
Create a name \ _variable.rb that returns.
First, assign ARGV [0] to name \ # + begin \ _src rubyname = ARGV [0] \ # + end \ _src And \ # + begin \ _src rubyputs "Hello # {name}." \ # + end \ _src
> ruby name_variable.rb Rudy
Hello Rudy.
Is output.
method
In Ruby, a function defines a method.
method can take 0 or more arguments. For example
def hello(name)
p name
end
> ruby hello_method.rb Rudy
Hello Rudy.
Create hello \ _method.rb that returns.
First, substitute ARGV [0] for name.
name = ARGV[0]
Then call the hello method
name = ARGV[0]
hello(name)
However, this gives an error because the hello method is not declared. So, create a hello method with one argument.
def hello(name)
puts "Hello #{name}."
end
name = ARGV[0]
hello(name)
with this
> ruby hello_method.rb Rudy
Hello Rudy.
Is output.
Chart type ruby-II (variable and method)
Recommended Posts