RubyGems Navigation menu

trope 0.0.0

# 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 meth add_book do |attributes_or_book | book = attributes_or_book.is_a?(Book) ? attributes_or_book : book.library = self @books # p library.add_book name: 'Book 1', isbn: 1 # => [#>] p library # => #>]> p library.books.first # => #]>> p library.books.first.isbn = nil # => nil p = nil # => Book::MissingNameError: name cannot be nil p library.books.first.library = nil # => Book::MissingLibraryError: library cannot be nil p library.books.first.isbn = ['array'] # => Book::InvalidIsbnError: isbn must be an instance of Integer or respond to :to_i p library = 123) # => Library::InvalidBooksError: books must be an instance of Array or respond to #to_a ``` ### Breakdown ```ruby object Book attr name -!wd 'Unnamed book' end ``` This says that I have an object `Book` that has an attribute `name` (`attr name`) that must either be an instance/subclass of `String` or be able to convert to an instance of `String` using `#to_s` (``). It is a required attribute that can never be set to nil (`!`), has a writer method (`w`), and defaults to 'Unnamed book'. The minus sign (`-`) indicates a 'switch' or 'option', must like most *nix command line programs. The example could also have been written like so: ```ruby object Book attr name -! -w -d 'Unnamed book' end ``` The above examples will transcompile into the following: ```ruby class Book class Error . The MIT License (MIT) - See LICENSE for further details. [docs]: [gems]: [source]:


  1. 0.0.0 - December 1, 2012 (14.5 KB)


  • Ryan Scott Lewis



SHA 256 checksum:


Total downloads 1,413

For this version 1,413

= Copy to clipboard Copied!




Required Ruby Version: None