module Bendy
The Bendy
library of useful code and odds and ends. These snippets of code have been useful to the Bendyworks team at times and so are collected here for ease of use. Please see individual docs for more information on usage.
We’re using refinements to _freedom patch_ Array in a safe way.
We’re using refinements to _freedom patch_ Hash in a safe way.
Bendy
module that _freedom patches_ Object and NilClass to add ‘try`, like in ActiveSupport
Constants
- VERSION
Public Instance Methods
get_deep(*fields)
click to toggle source
# File lib/bendy/hash.rb, line 17 def get_deep(*fields) fields.inject(self) {|acc,e| acc[e] if acc.is_a?(Hash)} end
inits()
click to toggle source
# File lib/bendy/array.rb, line 27 def inits (self.length + 1).times.map{ |i| self.take(i) } end
tails()
click to toggle source
# File lib/bendy/array.rb, line 14 def tails (self.length + 1).times.map{ |i| self.drop(i) } end
try(*a) { |self| ... }
click to toggle source
# File lib/bendy/object.rb, line 15 def try(*a, &b) if a.empty? && block_given? yield self else public_send(*a, &b) if respond_to?(a.first) end end