Cat and mouse become best friends. Unexpected..

3 Unexpected Behaviors using Ruby

Mehdi Farsi
Jan 22 · 3 min read
  • variables declared in a conditional block
  • String#to_i vs Integer(String)

Introduction

In Ruby, what I call an unexpected behavior is a behavior that doesn’t seem natural at first.

Return values within an ensure clause

In Ruby, the value of the last evaluated statement is used as return value of the called method if there is no explicit call to return

Variables declared in a conditional block

Variables declared in a conditional block that is never evaluated are initialised with a default nil value

NameError (undefined local variable or method `champ’ ..)

String#to_i vs Integer(String)

The String#to_i method is used to convert the string representation of a number to an Integer

ONE MORE THING ⬇

Feel free to subscribe here: www.rubycademy.com


rubycademy

E-Learning platform for Ruby and Ruby on Rails

Mehdi Farsi

Written by

Founder of www.rubycademy.com — I blog about Ruby & ROR - Paris

rubycademy

E-Learning platform for Ruby and Ruby on Rails