Skip to content

Instantly share code, notes, and snippets.

@kouno
Created June 5, 2012 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kouno/2878246 to your computer and use it in GitHub Desktop.
Save kouno/2878246 to your computer and use it in GitHub Desktop.
Inheritance of BigDecimal breaks is_a? function in JRuby
require "bigdecimal"
class Decimal < BigDecimal
end
# Inheritance breaks is_a? function
# Decimal.new("9876543210").is_a?(Decimal)
# => false
# jruby 1.6.7.2 (ruby-1.8.7-p357) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [darwin-x86_64-java]
puts "Decimal.new is a Decimal object?: #{Decimal.new("9876543210").is_a?(Decimal)}"
class SubString < String
end
# Inheriting from String works as expected.
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