Skip to content

Instantly share code, notes, and snippets.

@pauladam
Created April 19, 2013 00:27
Show Gist options
  • Select an option

  • Save pauladam/5417261 to your computer and use it in GitHub Desktop.

Select an option

Save pauladam/5417261 to your computer and use it in GitHub Desktop.
Re-opening Java classes from Jruby example
jr-test $: cat jr-test.rb
require 'java'
class java::lang::String
# redefine length to give random values
# instead of the correct one
def length
(rand() * 100).to_i
end
end
j_string = java::lang::String.new(ARGV.first)
puts j_string.length
jr-test $: ruby jr-test.rb a-string
53
jr-test $: ruby jr-test.rb a-string
41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment