Categories: None [Edit]
trope
# Trope
**[Documentation][docs] - [Gem][gems] - [Source][source]**
Prototyping language that transcompiles into pure Ruby code.
1. Build your concept in Trope.
2. Write specs.
3. Transcompile into Ruby.
4. Destroy Trope files.
5. Red, green, refactor.
## Install
> NOTE: Trope is not released yet, the gem is just a placeholder.
### Bundler: `gem 'trope'`
### RubyGems: `gem install trope`
## Example
Create `library.trope`:
```ruby
object Book
attr name -!wd 'Unnamed book'
attr isbn -w
attr library -w do
before write { @library.books.delete(self) unless @library.nil? }
after write { @library.books.push(self) unless @library.books.include?(self) }
end
end
object Library
attr books -d Array.new
meth add_book do |attributes_or_book |
book = attributes_or_book.is_a?(Book) ? attributes_or_book : Book.new(attributes_or_book)
book.library = self
@books << book
end
end
```
Now generate the Ruby code:
```sh
$ trope compile libary.trope
```
Those 15 lines will be transcompiled into the following pure Ruby code in `library.rb`:
```ruby
class Book
class Error < RuntimeError; end
class InvalidAttributesError < Error
def to_s
'attributes must be a Hash or respond to #to_h'
end
end
class MissingAttributeError < Error
def initialize(attr_name, attr_class)
@name, @class = attr_name.to_s, attr_class.to_s
end
def to_s
"attribute '#@name' does not exist for #@class"
end
end
class MissingNameError < Error
def to_s
'name cannot be nil'
end
end
class InvalidNameError < Error
def to_s
'name must be an instance of String or respond to :to_s'
end
end
class InvalidIsbnError < Error
def to_s
'isbn must be an instance of Integer or respond to :to_i'
end
end
class MissingLibraryError < Error
def to_s
'library cannot be nil'
end
end
class InvalidLibraryError < Error
def to_s
'library ...
Total
Ranking: 137,494 of 187,709
Downloads: 4,337
Daily
Ranking: 68,249 of 187,696
Downloads: 1
Downloads Trends
Ranking Trends
Num of Versions Trends
Popular Versions (Major)
Popular Versions (Major.Minor)
Depended by
| Rank | Downloads | Name |
|---|
Depends on
| Rank | Downloads | Name |
|---|---|---|
| 91 | 449,058,957 | rb-fsevent |
| 388 | 117,291,330 | guard-rspec |
| 414 | 111,577,649 | redcarpet |
| 478 | 95,456,996 | polyglot |
| 520 | 89,253,992 | treetop |
| 760 | 67,584,110 | fuubar |
| 1,329 | 30,585,372 | github-markup |
| 4,212 | 2,114,595 | version |
| 7,128 | 589,520 | guard-yard |
Owners
| # | Gravatar | Handle |
|---|---|---|
| 1 | RyanScottLewis |