Bro, do you even Ruby?
This is a ruby port of the popular brototype.js library that can be found here: https://github.com/letsgetrandy/brototype
You've got a deeply-nested set of objects that may or may not always be there. We've all seen something like this:
if params && params[:model] && params[:model][:id]
# do something
end
We all hate that, don't we?
So what if you could just type:
Brototype::Bro.new(params).i_can_haz(:model,:id)
Or better yet, how about:
Brototype::Bro.new(params).i_dont_always(:model,:id).but_when_i do |id|
puts id
end
Fetch nested properties by string or key:
Brototype::Bro.new(:foo => {:bar => 1}).i_can_haz(:foo,:bar)
Brototype::Bro.new('foo' => {'bar' => 1}).i_can_haz('foo','bar')
Brototype::Bro.new(@anon_class).brace_yourself('throws_error').here_come_the_errors do |e|
puts 'error ' + e + ' happened.'
end
Add this line to your application's Gemfile:
gem 'brototype'
And then execute:
$ bundle
Or install it yourself as:
$ gem install brototype
rake spec
- Fork it ( https://github.com/[my-github-username]/brototype/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request