This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{puts} = require 'sys' | |
MyClass = prototype ~> | |
@doSomething = -> 3 + 5 | |
foobar = new MyClass() | |
puts foobar.doSomething() | |
AnotherClass = prototype inherits MyClass ~> | |
constructor = -> @abc = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reverse apply. | |
Object::apply = (func, args) -> func.apply this, args | |
# Base model class. | |
class Model | |
has_many: (what) -> | |
@[what] = -> | |
how_many = @["number_of_#{what}"] | |
console.log "I have #{how_many} shiney #{what}!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Model | |
# Method used in a class context. | |
@has_many = (names) -> | |
# Define the accessor method. | |
@[names] = -> | |
# Retrieve stuff from table 'names' | |
class Account extends Model | |
@has_many 'emails' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A monkey-patch for ActionPack, which takes into account a POST's encoding. | |
# Browsers may specify this using a hidden _charset_ field, or in the Content-Type. | |
# Briefly tested on Rails 2.3.5 and Ruby 1.9.1p376. | |
class ActionController::Request < Rack::Request | |
# This is copied from Rack::Request. Rails overrides content_type, which the original relies on, | |
# thus breaking it, unfortunately. Instead, this version uses @env['CONTENT_TYPE']. | |
def media_type_params | |
return {} if @env['CONTENT_TYPE'].nil? | |
@env['CONTENT_TYPE'].split(/\s*[;,]\s*/)[1..-1]. |
NewerOlder