Currently, I am studying to get the Ruby engineer certification exam silver. It's about time for the exam, so I'll review the part that was caught in the mock exam.
HOGE = "hoge" HOGE.gsub!("hoge", "piyo") print HOGE
I thought that a warning would appear in this output result (because the constant was changed), but it was different. Warning statements are made for constant "reassignment", so you can change the value without warning for destructive method calls.
It's short, but what's this grammar? Output one character after? As a character string. Error if you write more than 2 characters. I have no idea what it's used for in my brain.
class Hoge < Kernel ; end
I get an error when I do this, because the Kernel is a module. Use include to inherit modules.
p "123abc".to_i => 123
I understood that strings should be integers, but I didn't know when there were non-integers. If non-integers are mixed, the character up to one character other than the integer is output as an integer. Therefore, even in the case of "123abc123" to_i, 123 is output.
a = [1,2,3,4] b = [1,3,5,7] p a || b => [1,2,3,4]
I thought the output was [1,2,3,4,5,7], but that is the case with a | b. a ||In the case of b, when a is true, a is spit out without evaluating b and the process ends.
puts "0123456789-".delete("^13-56-") => 13456-
"Delete matches 1 and 3 to 5 and 6-so you should delete this, I fully understand." ← I don't know If ^ is included in the regular expression, it will be "other than XX", so delete the character string "other than" that matches the above.
p 75.chr p "K".ord => "K" 75
chr method converts integers as character codes On the contrary, the ord method converts characters to integers that support character codes.