Glossary Flashcards
# Array.new constructor variable = \_\_\_\_(some_array)
Array.new
# Array.new constructor variable = \_\_\_\_(some_array)
Array.new
\_\_\_\_ do |arg| # Do something to each element, referenced as arg end
array.each
array.each ___ |arg|
# Do something to each element, referenced as arg
end
do
array.each do \_\_\_\_ # Do something to each element, referenced as arg end
|arg|
array.each do |arg| # Do something to each element, referenced as arg \_\_\_\_
end
[[1,2,3], [4,5,6], 7, [[8,9], 10]].____
=> [1,2,3,4,5,6,7,8,9,10]
flatten
[1,1,1,2,3,4,3,3].___
=> [1,2,3,4]
uniq
# Blocks that span only one line usually use the braces form objs.\_\_\_ { |obj| do_something }
method
# Blocks that span only one line usually use the braces form objs.method {\_\_\_ do_something }
|obj|
# Blocks that span only one line usually use the braces form objs.method \_\_ |obj| do_something \_\_
{ }
objs.method \_\_\_ |obj| # do first line # do second line # ... # do nth line end
do
objs.method do \_\_\_ # do first line # do second line # ... # do nth line end
|obj|
objs.method do |obj| # do first line # do second line # ... # do nth line \_\_\_
end
x __y // returns true if two things are equal
==
x__y // returns true if two things are not equal
!=
x __ y // returns true if x is less than or equal to y
x __ y // returns true if x is greater than or equal to y
> =
__
comment line
comment line
=end
=begin
=begin
comment line
comment line
__
=end
empty_hash = Hash.new
=> {}
my_hash = Hash.new(“The Default”)
my_hash[“random_key”]
=>__
“The Default”
empty_hash = Hash.new
=> {}
my_hash = Hash.new(“The Default”)
my_hash[“random_key”]
=>__
“The Default”
\_\_\_\_ do |arg| # Do something to each element, referenced as arg end
array.each
array.each ___ |arg|
# Do something to each element, referenced as arg
end
do
array.each do \_\_\_\_ # Do something to each element, referenced as arg end
|arg|
array.each do |arg| # Do something to each element, referenced as arg \_\_\_\_
end
[[1,2,3], [4,5,6], 7, [[8,9], 10]].____
=> [1,2,3,4,5,6,7,8,9,10]
flatten
[1,1,1,2,3,4,3,3].___
=> [1,2,3,4]
uniq
# Blocks that span only one line usually use the braces form objs.\_\_\_ { |obj| do_something }
method
# Blocks that span only one line usually use the braces form objs.method {\_\_\_ do_something }
|obj|
# Blocks that span only one line usually use the braces form objs.method \_\_ |obj| do_something \_\_
{ }
objs.method \_\_\_ |obj| # do first line # do second line # ... # do nth line end
do
objs.method do \_\_\_ # do first line # do second line # ... # do nth line end
|obj|
objs.method do |obj| # do first line # do second line # ... # do nth line \_\_\_
end
x __y // returns true if two things are equal
==
x__y // returns true if two things are not equal
!=
x __ y // returns true if x is less than or equal to y
x __ y // returns true if x is greater than or equal to y
> =
__
comment line
comment line
=end
=begin
=begin
comment line
comment line
__
=end
# Hash.new constructor my_hash = \_\_\_([default_value])
Hash.new
empty_hash = Hash.new
=> {}
my_hash = Hash.new(“The Default”)
my_hash[“random_key”]
=>__
“The Default”
# Hash literal notation my_hash = { \_\_ => value1, :key2 => value2, 3 => value 3 }
“key1”
# Hash literal notation my_hash = { "key1" => value1, :key2 => value2, 3 => value 3 }
:key2
# Hash literal notation my_hash = { "key1" => value1, :key2 => value2, \_\_ => value 3 }
3
my_hash = {
__
}
key1: value1,
key2: value2
if ___
puts “I get printed!”
end
I get printed!
true
___ false
puts “I get printed!”
end
I get printed!
unless
x = 5 if x > 5 print "I am big!" \_\_\_ x == 5 print "I am medium!" else print "I am small!" end
I am medium!
elsif
x = 5 if x > 5 print "I am big!" elsif x == 5 print "I am medium!" \_\_\_ print "I am small!" end
I am medium!
else
i = 1
___ i
while
counter = 3
___ counter
until
__ number in (0..5)
puts number
end
0 1 2 3 4 5
for
for number __ (0..5)
puts number
end
0 1 2 3 4 5
in
my_array = [“Matz”, “chunky”, “bacon”]
for item in __
puts item
end
Matz
chunky
bacon
my_array
10 __ 3
=> 1
%
9.99.___
=> 9
floor
45.4.___
=> 46
(4 - 1.9).___
=> 3
ceil
__
=> 3.14159265358979
Math::PI
___(100)
=> 10.0
___(5+4)
=> 3.0
Math.sqrt
___ sum(x,y)
x + y
end
sum(13, 379)
=> 392
def
3.times { ___ “Hello!” }
Hello!Hello!Hello!
3.times { ___ “Hello!” }
Hello!
Hello!
Hello!
puts
a = ["4"] \_\_\_ a when 1..4, 5 puts "It's between 1 and 5" when 6 puts "It's 6" when String puts "You passed a string" else puts "You gave me #{a} -- I have no idea what to do with that." end
=> You gave me 4 – I have no idea what to do with that.
case
a = ["4"] case a \_\_\_ 1..4, 5 puts "It's between 1 and 5" \_\_\_ 6 puts "It's 6" \_\_\_ String puts "You passed a string" else puts "You gave me #{a} -- I have no idea what to do with that." end
=> You gave me 4 – I have no idea what to do with that.
when
a = ["4"] case a when 1..4, 5 puts "It's between 1 and 5" when 6 puts "It's 6" when String puts "You passed a string" \_\_\_ puts "You gave me #{a} -- I have no idea what to do with that." end
=> You gave me 4 – I have no idea what to do with that.
else
grade = 88
status = grade >= 70 ___ “pass” : “fail”
=> pass
?
grade = 88
status = grade >= 70 ? “pass”___ “fail”
=> pass
:
ne_to_ten = (1..10).to_a
one_to_ten.___ do |num|
print (num**2).to_s + “ “
end
1 4 9 16 25 36 49 64 81 100
each
ne_to_ten = (1..10).to_a
one_to_ten.each ___ |num|
print (num**2).to_s + “ “
end
1 4 9 16 25 36 49 64 81 100
do
3.____ do
puts “I’m in the loop!”
end
puts “I’m out the loop!”
times
3.times ____
puts “I’m in the loop!”
end
puts “I’m out the loop!”
do
空のハッシュを作成
scores = ____
{}
# キー"Alice"、値80のペアを追加 scores\_\_\_\_ = 80
[“Alice”]
# キー"Alice"、値80のペアを追加 scores["Alice"] \_\_\_
= 80
# キー"Alice"の値を取り出し p scores\_\_\_\_
[“Alice”]
# 3つのキー(name, email, address)+値からなるハッシュを作成 user = { \_\_\_ => "k-sato", \_\_\_ => "k-sato@foo.xx.jp", \_\_\_ => "Tokyo" }
:name :email :address
# キー:nameの値を取り出し p user\_\_\_
[:name]