No commit activity in last 3 years
No release in over 3 years
Dynamic options.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Declarative::Option

Dynamic options to evaluate at runtime.

Installation

Gem Version Build Status

Add this line to your application's Gemfile:

gem 'declarative-option'

Runs with Ruby >= 1.9.3.

See travis for JRuby and Rubinius current status.

Option

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.(Object.new, *args) #=> 2354383

Same with objects marked with Callable.

class CallMe
  include Declarative::Callable

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

option = Declarative::Option(Callable.new) #=> "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.

License

Copyright (c) 2017 by Nick Sutterer apotonick@gmail.com

Uber is released under the MIT License.