Dynamic options to evaluate at runtime.


Gem Version

Add this line to your application's Gemfile:

gem 'mega-options'

Runs with Ruby >= 1.9.3.


Pass any value to Option, it will wrap it accordingly and make it executable, so you can call the value at runtime to evaluate it.

It works with static values.

option = Declarative::Option(false)
option.(context, *args) #=> false

When passing in a :symbol, this will be treated as a method that's called on the context. The context is the first argument to Option#call.

option = Declarative::Option(:object_id)
option.(, *args) #=> 2354383

Same with objects marked with Callable.

class CallMe
  include Declarative::Callable

  def call(context, *args)
    puts "hello!"

option = Declarative::Option( #=> "hello!"

And of course, with lambdas.

option = Declarative::Option( ->(context, *args) { puts "yo!" } )
option.(context) #=> yo!

All call arguments behind the first are passed to the wrapped value.


Copyright (c) 2017 by Nick Sutterer [email protected]

Uber is released under the MIT License.