Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hakanensari/double

Double allows you to use a constant before it is defined when metaprogramming
https://github.com/hakanensari/double

Last synced: 23 days ago
JSON representation

Double allows you to use a constant before it is defined when metaprogramming

Awesome Lists containing this project

README

        

# Double

[![travis][status]][travis]

## Description

Something can be [familiar, yet foreign at once][uncanny].

**Double** allows you to reference a constant before it is defined—a useful
trick when metaprogramming.

## Usage

A contrived example:

```ruby
class Jekyll
extend Double

# Gets/Sets the alter ego of the class.
#
# klass - A Class.
#
# Returns the Class alter ego.
def self.alter_ego(klass = nil)
klass ? @alter_ego = klass : @alter_ego
end
end

# Open the class and set the alter ego:
class Jeykll
alter_ego Hyde
end

Jekyll.alter_ego # => #

# But who is this Hyde? Define him:
class Hyde; end

Jekyll.alter_ego # => Hyde
```

[status]: https://secure.travis-ci.org/hakanensari/double.png
[travis]: http://travis-ci.org/hakanensari/double
[uncanny]: http://www-rohan.sdsu.edu/~amtower/uncanny.html