ruby Exercise Memo II (variable and method)

Purpose

Let's actually write the code of ruby. This time is the second.

Theme 1

Substitute the received argument ARGV [0] into a variable called name and write a code to issue it. (Issues in https://qiita.com/daddygongon/items/c51f3e0695174bb3c508)

The code I wrote this time (hello \ _variable.rb)


name = ARGV[0]
puts "Hello #{name}."

Commentary

Nothing to say about the code itself. By the way, it seems that you don't need a type declaration.

Theme 2

> ruby hello_method.rb Rudy
Hell Rudy.

Create a hello method that returns. (Issues at the link above)

The code I wrote this time (hello \ _method.rb)


#!/usr/bin/env ruby

def hello name
  puts "Hello #{name}."
end

name = ARGV[0]
hello name

Commentary

method can be written with def-end. The argument () can be omitted.

Bonus (TDD)

There is a story about TDD (Test Driven Development) in the previous link (here). Let's read it.

Reference material

Chart type ruby-II (variable and method)


Recommended Posts

ruby Exercise Memo II (variable and method)
variable and method
Be careful about Ruby method calls and variable references
ruby exercise memo I (puts)
Ruby design pattern template method pattern memo
ruby exercise memo VI (hello class)
String output method memo in Ruby
Ruby memo
Difference between Ruby instance variable and local variable
ruby constant variable
Ruby to_s method
[Ruby] How to use gsub method and sub method
[Ruby] slice method
[Ruby] end_with? method
[Ruby] Method memorandum
[Ruby] "Reference to object" and "Contents of variable"
[Ruby] initialize method
Ruby build method
[wip] Ruby memo
Ruby and Gem
Ruby accessor method
ruby map method
[Technical memo] About the advantages and disadvantages of Ruby
[Ruby] Classes and instances
Ruby Learning # 30 Initialize Method
Symbols and Destructive Ruby
[Ruby] Big Decimal and DECIMAL
Java learning memo (method)
ruby basic syntax memo
[Java ~ Method ~] Study memo (5)
Ruby Thread # [] = method notes
definition of ruby method
Ruby classes and instances
Ruby inheritance and delegation
Ruby variables and methods
Variable type in ruby
[Ruby] Method definition summary
[Ruby] Questions and verification about the number of method arguments