ruby.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
If you are interested in the Ruby programming language, come join us! Tell us about yourself when signing up. If you just want to join Mastodon, another server will be a better place for you.

Administered by:

Server stats:

1.1K
active users

If you're starting an IRB session inside of an `Class.new { include TheModule }.new` which extends a module, what would you expect `self.inspect` to return?

The `Class.new.tap { |klass| klass.include(context) }.new` is necessary so the resulting context object gets access to both the module's instance methods *and* it's constants. If anyone knows of a better way to wrap a module into an instance context for IRB, feel free to correct me here.

I seem to remember the old school way was to create a new Object.new, then access it's meta-class via `class << obj; self; end`, and then include the module into the meta-class, which was a bit too magical, but prevented `self.inspect` from returning `#<#<Class: ...>>` which looks confusing vs. regular old `#<Object:...>`.

postmodern

Cool trick I just discovered, transparently forward `const_missing` of an object to another module without adding another line to the backtrace:

obj.singleton_class.define_singleton_method(:const_missing,&mod.method(:const_missing))