Sha256: e7fc414f713a094cda2d35cd65035cfe760a0e9948e8ecbd972bcf39ba1bba82

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

= lazy_const

[![Build Status](https://secure.travis-ci.org/rmg/feature_definitions.png?branch=master)](http://travis-ci.org/rmg/feature_definitions)

A simple way of defining lazy evaluated, const-like instances of a class.

Thanks to Travis-CI, tested on:
  - "1.8.7"
  - "1.9.2"
  - "1.9.3"
  - "2.0.0"
  - jruby-18mode # JRuby in 1.8 mode
  - jruby-19mode # JRuby in 1.9 mode
  - rbx-18mode
  - rbx-19mode

== Installation

  gem 'lazy_const'

== Example

=== Basic Usage

  class Group
    extend LazyConst
    lazy_const :EVERYONE do
      new("Everyone")
    end
    def initialize(name)
      @name = name
      @members = []
    end
    def add_user(user)
      @members << user
    end
  end

  class User; end

  class Registrar
    def new_user(name)
      user = User.new(name)
      Group.EVERYONE.add_user(user)
      user
    end
  end

=== Testing with RSpec

spec/spec_helper.rb:
  require 'lazy_const/spec'

lib/some_class.rb:
  class SomeClass
    extend LazyConst
    lazy_const :IMPORTANT_INSTACE do
      new(:hotness)
    end
  end

spec/some_spec.rb:
  describe MyClass do
    defines_const :IMPORTANT_INSTANCE
    # ...
  end

== Contributing to lazy_const
 
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
* Fork the project.
* Start a feature/bugfix branch.
* Commit and push until you are happy with your contribution.
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2013 Ryan Graham. See LICENSE.txt for further details. (TL;DR: MIT license)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lazy_const-0.1.3 README.rdoc