Skip to content

Instantly share code, notes, and snippets.

@dekz
Forked from kouno/gist:2878246
Created June 5, 2012 23:20
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 dekz/2878757 to your computer and use it in GitHub Desktop.
Save dekz/2878757 to your computer and use it in GitHub Desktop.
Inheritance of BigDecimal breaks is_a? function in JRuby
~/tmp % jruby -v
jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
~/tmp % jruby zz.rb
Decimal.new is a Decimal object?: false
SubString.new is a SubString object?: true
~/tmp % jruby -v
jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
~/tmp % jruby --1.9 zz.rb
Decimal.new is a Decimal object?: false
SubString.new is a SubString object?: true
~/tmp % jruby -v
jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
~/tmp % jruby zz.rb
Decimal.new is a Decimal object?: false
SubString.new is a SubString object?: true
~/tmp % ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
~/tmp % ruby zz.rb
Decimal.new is a Decimal object?: true
SubString.new is a SubString object?: true
~/tmp % ruby -v
rubinius 2.0.0dev (1.8.7 4f53f0ce yyyy-mm-dd JI) [x86_64-apple-darwin11.3.0]
~/tmp % ruby zz.rb
Decimal.new is a Decimal object?: true
SubString.new is a SubString object?: true
require "bigdecimal"
class Decimal < BigDecimal
end
puts "Decimal.new is a Decimal object?: #{Decimal.new("9876543210").is_a?(Decimal)}"
class SubString < String
end
puts "SubString.new is a SubString object?: #{SubString.new("test").is_a?(SubString)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment