Skip to content

Instantly share code, notes, and snippets.

View ravinggenius's full-sized avatar
🤔
likely thinking

Thomas Ingram ravinggenius

🤔
likely thinking
View GitHub Profile
@ravinggenius
ravinggenius / README.md
Last active January 4, 2016 13:19
Rip code loading

System.require uses the following loaders:

package loader (only if module is part of a package)

load package module relative to ./lib/* (first-party) or ./vendor/**/lib/* (third-party)

System.require('package/file')

filesystem loader (available in a package or not)

use Ecto.Query
query = from w in Weather,
where: w.prcp > 0 or w.prcp == nil,
where: w.code in 27500..27599,
select: w
Repo.all(query)
class Animal
attr_reader :name
attr_reader :family
def initialize(name, code)
@name = name
@family = family
end
def to_a
# USAGE
Foo = class (Struct.new(:name, :address)) {
compare_by(:name)
order_by(:address, :name)
}
# USAGE
class Foo < Struct.new(:name, :address)
extend HelperMacros
compare_by :name
order_by :address, :name
end
@ravinggenius
ravinggenius / http.rb
Created November 9, 2013 20:32
valid metaprogramming?
class HTTP
def request(method, options)
# stuff...
end
[
:get,
:head,
:put,
:post

Getting started with Rip

  1. Clone the repo: $ git clone git://github.com/rip-lang/rip.git
  2. Change into directory: $ cd rip
  3. Install dependencies (requires Ruby 2): $ bundle install

Rip comes with a command-line binary at ./bin/rip. Type ./bin/rip help to see how to use Rip. Specifically the current goal is to validate the generated syntax tree by trying to break the debug output. You can run .bin/rip debug -t syntax [file] to produce a human-readable (though large) representation of the syntax tree. If you get an error, please open an issue with the exact Rip source code and a copy of the error message.

You can find out more about Rip at Rip's website (work-in-progress) and view some (hopefully still valid) examples on GitHub to get going. Please note that some examples may be outdated; pull-requests are welcome :). Also let me know if you have any trouble or are unsure about some

require 'parslet'
require 'pry'
module Rip::Compiler
class AST < Parslet::Transform
attr_reader :origin
def initialize(origin)
@origin = origin
end
#!/usr/bin/env ruby
phrase = ARGV.first || 'I am such a tool'
while true
system "say #{phrase}"
sleep (1..10).to_a.sample
end
class FunctionalLexer
TOKENS = [
WhitespaceToken,
DigitsToken,
WordToken,
UnknownToken # keep last
]
include Enumerable