No commit activity in last 3 years
No release in over 3 years
Forwards methods to hash as keys
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.0.0
~> 1.8.3
~> 3.12
~> 2.8.0
 Project Readme

Forwardable Content Hash Binder

A small helper class for exposing Hashes to ERB templates or other binding scoped scenarios.

Gem Version

Installation

gem install forwardable_content_hash_binder

Usage

Access top level keys as methods

require 'forwardable_content_hash_binder'

fchb = ForwardableContentHashBinder.new("title" => "Best Gem Ever", "body" => "This gem has the potential to save lives")

fchb.title
 => "Best Gem Ever"

If any key in the Hash is a Proc, it will execute it on call

fchb["Time"] = Proc.new { Time.new}
 => #<Proc:0x00000002345a10@(irb):5> 
fchb.time
 => 2013-07-02 08:41:49 -0400
fchb.time
 => 2013-07-02 08:42:32 -0400

Pass the binding to ERB for easy templating

fchb.get_binding
 => #<Binding:0x007fb1fb0570d0>

require 'erb'
template = '<h1> <%= title %> </h1> <p> <%= body %> at <%= time %> </p>'
ERB.new(template).result(fchb.get_binding)
 => "<h1> Best Gem Ever </h1> <p> This gem has the potential to save lives at 2013-07-02 08:43:02 -0400 </p>"