Sha256: bce15990ed91a2543cf81e988953992a56145f31e8f83957ce5fb7f97fc48d2b

Contents?: true

Size: 1.47 KB

Versions: 27

Compression:

Stored size: 1.47 KB

Contents

class Hash
  begin
    method "to_options"
  rescue
    def to_options
      inject(Hash.new){|h, kv| h.update kv.first.to_s.to_sym => kv.last}
    end
    def to_options!
      replace to_options
    end
  end

  begin
    method "to_string_options"
  rescue
    def to_string_options
      inject(Hash.new){|h, kv| h.update kv.first.to_s => kv.last}
    end
    def to_string_options!
      replace to_string_options
    end
  end

  begin
    method "reverse_merge"
  rescue
    def reverse_merge other
      other.merge self
    end
    def reverse_merge! other
      replace reverse_merge(other)
    end
  end

  begin
    method "slice"
  rescue
    def slice(*keys)
      allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
      reject { |key,| !allowed.include?(key) }
    end
  end

  begin
    method "slice!"
  rescue
    def slice!(*keys)
      replace(slice(*keys))
    end
  end
end

class Object
  begin
    method "returning"
  rescue
    def returning value, &block
      block.call value
      value
    end
  end
end

class Object
  def singleton_class &block
    @singleton_class ||=
      class << self
        self
      end
    block ? @singleton_class.module_eval(&block) : @singleton_class
  end
end

class String
  begin
    method 'underscore'
  rescue
    def underscore
      gsub(/::/, '/').
        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
        gsub(/([a-z\d])([A-Z])/,'\1_\2').
        tr("-", "_").
        downcase
    end
  end
end

Version data entries

27 entries across 25 versions & 13 rubygems

Version Path
ThiagoLelis-backgroundjob-1.0.3 lib/bj/stdext.rb
ThiagoLelis-backgroundjob-1.0.4 lib/bj/stdext.rb
ThiagoLelis-bj-utc-1.0.1 lib/bj/stdext.rb
ThiagoLelis-bj-utc-1.0.2 lib/bj/stdext.rb
ambethia-bj-1.2.1 lib/bj/stdext.rb
averell23-bj-1.0.2 lib/bj/stdext.rb
bricooke-bj-1.0.2 lib/bj/stdext.rb
jcnetdev-bj-1.0.33 lib/bj/stdext.rb
jcnetdev-bj-1.0.38 lib/bj/stdext.rb
sevenwire-bj-1.0.1 lib/bj/stdext.rb
sevenwire-bj-1.0.2 lib/bj/stdext.rb
sevenwire-bj-1.0.4 lib/bj/stdext.rb
blackhoundjob-1.0.2 lib/bj/stdext.rb
SciMed-bj-1.3.0 lib/bj/stdext.rb
SciMed-bj-1.2.5 lib/bj/stdext.rb
SciMed-bj-1.2.4 lib/bj/stdext.rb
bj_fixed_for_rails3-1.0.2 lib/bj/stdext.rb
vibes-bj-1.2.2 spec/rails_root/vendor/plugins/bj/lib/bj/stdext.rb
vibes-bj-1.2.2 lib/bj/stdext.rb
vibes-bj-1.2.1 lib/bj/stdext.rb