Sha256: 7be616612df778287f8f1d11ca5fc67e1387032625855e36ef83346bdfe8f423

Contents?: true

Size: 1.22 KB

Versions: 10

Compression:

Stored size: 1.22 KB

Contents

Collection of various utility classes and standard library extensions for Ruby language.

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

``` ruby
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.

``` ruby
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

``` ruby
def complex_calculation
  2 * 2
end
cache_method :complex_calculation
```

## OpenConstructor - adds mass assignment to any class

``` ruby
class TheClass
  include RubyExt::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

``` bash
gem install ruby_ext
```

``` ruby
require 'ruby_ext'
```

## License

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby_ext-0.5.10 readme.md
ruby_ext-0.5.9 readme.md
ruby_ext-0.5.8 readme.md
ruby_ext-0.5.7 readme.md
ruby_ext-0.5.6 readme.md
ruby_ext-0.5.5 readme.md
ruby_ext-0.5.4 readme.md
ruby_ext-0.5.3 readme.md
ruby_ext-0.5.2 readme.md
ruby_ext-0.5.1 readme.md