Ruby variables and functions (methods)


Preface (Introduction)

This article is related to Part 6 of the Special Lecture on Multiscale Simulation. We will proceed according to Chart type Ruby.

This time, we will learn about Ruby variables and methods according to Chart expression ruby-II (variable and method).



Ruby doesn't require type declarations for variables, so you can use it this way as well.

x = 'Ruby'
x = 19
x = false

You can also assign ARGV [0] to a variable as in Last article.


name = ARGV[0]
puts "hello #{name}"
> ruby name_variable.rb W
-> hello W


Function in Ruby means to define method. This seems to be because everything in Ruby is an object.

Use your hands to remember.


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

name = ARGV[0]
> ruby hello_method.rb W                                                                   
-> Hello W.                                                                                  

Reference material

Ruby – Wikipedia

Recommended Posts

Ruby variables and functions (methods)
Ruby variables and methods
Functions and methods
Ruby: Differences between class methods and instance methods, class variables and instance variables
[Ruby] Singular methods and singular classes
Ruby methods and classes (basic)
[Ruby] Singular methods and singular classes
Ruby standard input and various methods
Ruby Learning # 15 Methods
About Ruby variables
Ruby and Gem
About Ruby methods
[Ruby] Classes and instances
Symbols and Destructive Ruby
[Ruby] Big Decimal and DECIMAL
Ruby Learning # 31 Object Methods
About Ruby instance methods
Ruby classes and instances
[Swift] Constants and variables
[Ruby] methods, instance methods, etc ...
[Java] Variables and types
Basic methods of Ruby hashes
Coding methods and refactoring principles
Basic methods of Ruby arrays
(Note) Java classes / variables / methods
[Java] Generics classes and generics methods
Java programming (variables and data)
rails path and url methods
Ruby syntax errors and countermeasures
[Ruby] Exception handling in functions
Use ruby variables in javascript.
Difference between variables and instance variables
Three Bit Manipulation Methods (Ruby)
About Ruby hashes and symbols
Ruby C extension and volatile
Summarize Ruby and Dependency Injection
About pluck and ids methods
Java methods and method overloads
What are Ruby class methods?
About Ruby and object model
[Programming Complete] §4 Variables and constants
About Ruby classes and instances
About instance variables and attr_ *
Creating Ruby classes and instances
Java abstract methods and classes
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
[Ruby] Difference between get and post
Write Ruby methods using C (Part 1)
[Ruby] present/blank method and postfix if.
Java Primer Series (Variables and Types)
About the equals () and hashcode () methods
[Ruby] Difference between is_a? And instance_of?
About Ruby single quotes and double quotes
How to call classes and methods
Ruby convenience methods for fledgling engineers
Organize classes, instances, and instance variables
[Ruby] then keyword and case in
[Ruby basics] split method and to_s method
About Ruby product operator (&) and sum operator (|)
Write keys and values in Ruby
[Ruby] If and else problems-with operators-