Sha256: 5de3d364fadce1263feb9905baa086cbbbfda402867f4a15a1a36092c6b3c302

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

# Ruby extensions
**ruby_ext** is a collection of various utility classes and standard library extensions for the Ruby language.

## must - assertion tool, kind of RSpec assertions in runtime code

    1.must_be.in 1..2
    "a".must_be.in 'a', 'b', 'c'
    key.must_be.a String
    value.must_not_be.nil
    must_be.never_called  
    a.must_be == b

## inherit - combines include & extend in one
Do you remember this *def self.included(base) ... end* hack? You don't need it anymore.

    module Feature
      def cool_method; end        
      class_methods do
        def cool_class_method; end
      end
    end            
  
    class TheClass
      inherit Feature
    end
  
    TheClass.new.cool_method
    TheClass.cool_class_method  
  
## cache_method & synchronize_method

    def complex_calculation
      2 * 2
    end
    cache_method :complex_calculation

    def money_transfer amount
      @from -= amount
      @to += amount
    end
    synchronize_method :money_transfer

## OpenConstructor - adds mass assignment to any class
  
    class TheClass
      include OpenConstructor
      attr_accessor :a, :b
    end

    o = TheClass.new.set a: 'a', b: 'b'
    o.a => 'a'
    o.to_hash => {a: 'a', b: 'b'}

## More

These are just a small part of all handy methods and extensions, for more details please go to specs.

# Usage

    $ sudo gem install ruby_ext
  
    require 'ruby_ext'

Copyright (c) Alexey Petrushin, http://petrush.in, released under the MIT license.

# TODO

- config.development{} should raise 'invalid usage'

[ioc]: http://en.wikipedia.org/wiki/Inversion_of_control

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby_ext-0.4.25 readme.md
ruby_ext-0.4.24 readme.md
ruby_ext-0.4.23 readme.md
ruby_ext-0.4.22 readme.md
ruby_ext-0.4.21 readme.md