From: nobu@... Date: 2016-12-06T15:27:05+00:00 Subject: [ruby-core:78521] [Ruby trunk Feature#13009] Implement fetch for Thread.current Issue #13009 has been updated by Nobuyoshi Nakada. `Thread.current` just returns a `Thread` instance, so it should be `Thread#fetch` method. https://github.com/ruby/ruby/compare/trunk...nobu:feature/Thread%23fetch ---------------------------------------- Feature #13009: Implement fetch for Thread.current https://bugs.ruby-lang.org/issues/13009#change-61903 * Author: David Butler * Status: Open * Priority: Normal * Assignee: ---------------------------------------- It's a common idiom to use a fiber-local variable, but return a default value if it hasn't been assigned. Here's an example of Ruby code I would expect to be able to write: ~~~ ruby def feature_enabled? Thread.current.fetch(:feature_enabled, true) end ~~~ Unfortunately, Thread.current does not implement fetch, like Hash does. So I have to write the more verbose: ~~~ ruby def feature_enabled? Thread.current.key?(:feature_enabled) ? Thread.current[:feature_enabled] : true end ~~~ Thanks for your consideration! -- https://bugs.ruby-lang.org/ Unsubscribe: