Open a REPL within the context of any Ruby object. Originally written for the TimeBoss gem.
Installation
Add this line to your application's Gemfile:
# update with the version of your choice
gem 'shellable'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install shellable
Usage
Imagine you're building a new Ruby library, and you'd like to provide users with a way to experiment with that new library from the inside.
When developing the TimeBoss
gem, I wanted to create a Rake task to do just that.
require 'timeboss/calendars'
calendar = TimeBoss::Calendars[:broadcast]
# => #<TimeBoss::Calendars::Broadcast:0x007fea08a40408 @basis=TimeBoss::Calendars::Broadcast::Basis>
Once the desired target object for our REPL has been created, we can simply make it "shellable":
require 'shellable'
Shellable.open(calendar)
To check out a real-life example, head over to the TimeBoss timeboss:calendars:*:repl
task definition.
$ rake timeboss:calendars:broadcast:repl
2.4.1 :001 > this_week
=> #<TimeBoss::Calendar::Week start_date=2020-08-10, end_date=2020-08-16>
2.4.1 :002 > parse('2020Q4..2021Q2')
=> #<TimeBoss::Calendar::Period[#<TimeBoss::Calendar::Quarter start_date=2020-09-28, end_date=2020-12-27>..#<TimeBoss::Calendar::Quarter start_date=2021-03-29, end_date=2021-06-27>] start_date=2020-09-28, end_date=2021-06-27>
2.4.1 :003 >
Problems?
Please submit an issue. We'll figure out how to get you up and running with Shellable as smoothly as possible.