New Features & Tips Flashcards
Is this code valid?
def: increment(x) = x + 1
yes.
Ruby 3 new feature. Enless method
p increment(42) #=> 43
user = { name: ‘Oliver’, age: 29, role: ‘CTO’ }
in this code how you will print name and age pair alone?
user.except(:role)
Ruby 3 feature : except method
earlier we need to use active support in rails to do that
Is that possible to measure the processing time in IRB?
yes. add this measure command in IRB
New feature of Ruby 3
irb(main):001:0> 3 => 3 irb(main):002:0> measure TIME is added. => nil irb(main):003:0> 3 processing time: 0.000058s
Is it possible to color the Ruby IRB text?
class String def red "\e[31m#{self}\e[0m" end
def green
“\e[32m#{self}\e[0m”
end
end
puts “Red again!”.red
puts “Green again!”.green
puts “Mixed %s with %s!” % [“red”.red, “green”.green]
What is the alternate why to execute this code? def play while !exceeded_max_guesses? .... end end
Instead of a while not, we can simply use until:
until exceeded_max_guesses?
….
end