Created
September 30, 2025 07:47
-
-
Save lucianghinda/17edff4b5485109b9fd5ed400d862e7a to your computer and use it in GitHub Desktop.
BasicObject constant lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bundler/inline' | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem "minitest" | |
| end | |
| require "minitest/assertions" | |
| module TestHelpers | |
| def self.extended(base) | |
| base.extend Minitest::Assertions | |
| base.extend Counter | |
| end | |
| module Counter | |
| def assertions | |
| @assertions ||= 0 | |
| end | |
| def assertions=(n) | |
| @assertions = n | |
| end | |
| end | |
| end | |
| extend TestHelpers | |
| class MyBasicWithRelativePath < BasicObject | |
| def demo_raises_exception | |
| String.new("hello from basic object") | |
| end | |
| end | |
| class MyBasicWithAbsolutePath < BasicObject | |
| def demo_it_works | |
| ::String.new("hello from basic object") | |
| end | |
| end | |
| class MyObject < Object | |
| def demo_works_on_object | |
| String.new("hello from object") | |
| end | |
| end | |
| my_object = MyObject.new | |
| puts my_object.demo_works_on_object | |
| my_basic_object = MyBasicWithRelativePath.new | |
| assert_raises(NameError) { my_basic_object.demo_raises_exception } | |
| my_basic_object = MyBasicWithAbsolutePath.new | |
| puts my_basic_object.demo_it_works |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment