Follow

Ruby tip:

class Foo
def self.value
@value ||= defined?(super) ? super : DEFAULT_VALUE
end
end

this will turn Foo.value into a value you can configure per class (with a default), and you'll automatically inherit the superclass' value

@zenspider that’s shared across all (sub/super)classes, no? this can be different per class

@judofyr only from where it is assigned and down. Not up or over.

Sign in to participate in the conversation
Ruby.social

A Mastodon instance for Rubyists & friends