感謝のプログラミング 10000時間

たどり着いた結果(さき)は、感謝でした。

About the method of Ruby

<スポンサーリンク>

まだ全然書けないけれど、3年くらい毎日続ければきっと・・・!!

About Ruby

Ruby is object-oriented language.
primitive type doesn't exist.
Everything is object.

The naming rule of Ruby

The class name and module name begin with big letter.
For example,

class HogeClass

end
module HogeModule

end

The method name begin with lower case and break character is "_".
This is called snake case.
For example,

def hoge_method

end

The method witch judge truth or falsity has "?" character at the foot of it.
For example,

def happy?
	true
end

Definitional identity of method

The construction of method is as below.

def method_name(demmy argument...)
   ...
end

Sample Code of using method.

def hello(friends)
	friends.each do |name|
		puts "Hello, #{name.capitalize}"
	end
end

puts 'start!'
friends = ['SHO322', 'YUTA', 'KANA']

hello(friends)

puts 'end!'

This Rusult is...

C:\coding\ruby>ruby hello.rb
start!
Hello, Sho322
Hello, Yuta
Hello, Kana
end!

The way of calling method

receiver.method_name

if you want to read the text file,
write code as below.

File.open 'test.txt' do |file|
	puts file.read
end

the loaded file is this.

hoge
fuga
boo
yahoo

and result is...

C:\coding\ruby>ruby hello.rb
hoge
fuga
boo
yahoo

Return value of method

return value of method is the value of expression which is valued at the end of method.