Skip to content

Instantly share code, notes, and snippets.

@nimish-mehta
Created May 4, 2017 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimish-mehta/b6b7d49711eafbb3fcb7f50fd5c79849 to your computer and use it in GitHub Desktop.
Save nimish-mehta/b6b7d49711eafbb3fcb7f50fd5c79849 to your computer and use it in GitHub Desktop.
Matching Fixnum with integer in different ruby versions
➜ ruby ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin16.0]
➜ ruby ruby test_fixnum_2.rb
Found a number
Fixnum
1
➜ ruby ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin15]
➜ ruby ruby test_fixnum_2.rb
Found an integer
Fixnum
1
➜ ruby ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin15]
➜ ruby ruby test_fixnum_2.rb
Found a number
Integer
1
arg = 1
case arg
when Integer then
puts "Found a number"
puts arg.class
puts arg.to_i
else
puts "Could not match"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment