Skip to content

Instantly share code, notes, and snippets.

@yancya
Created May 21, 2025 14:49
Show Gist options
  • Save yancya/bc9aace385c90b586ebec8079dfe0f3b to your computer and use it in GitHub Desktop.
Save yancya/bc9aace385c90b586ebec8079dfe0f3b to your computer and use it in GitHub Desktop.
class A
def initialize
@tmp = 1
end
def to_s
"#{@tmp}"
end
end
class B
def to_s
A.new.to_s
end
end
puts B.new.to_s #=> 1
@yancya
Copy link
Author

yancya commented May 21, 2025

$ ruby -v
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
$ ruby hoge.rb
1

@yancya
Copy link
Author

yancya commented May 21, 2025

$ ruby -v
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [arm64-darwin24]
$ ruby hoge.rb 
1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment