Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created April 25, 2010 17:14
Show Gist options
  • Save jashkenas/378545 to your computer and use it in GitHub Desktop.
Save jashkenas/378545 to your computer and use it in GitHub Desktop.
# The Ruby...
def change_state(object_id, new_state)
object = find(object_id)
object.state = new_state
object.save
object
end
# The CoffeeScript with "returning"...
change_state: (object_id, new_state) ->
returning object: find object_id
object.state: new_state
object.save()
# The CoffeeScript with named result parameters...
change_state: (object_id, new_state) -> (object)
object: find object_id
object.state: new_state
object.save()
# An example from the language implementation with "returning"...
free_variable: ->
returning @temp_var
while @check @temp_var
ordinal: 1 + parseInt @temp_var.substr(1), 36
@temp_var: '_' + ordinal.toString(36).replace(/\d/g, 'a')
@variables[@temp_var]: 'var'
# An example from the language implementation with named result parameters...
free_variable: -> (@temp_var)
while @check @temp_var
ordinal: 1 + parseInt @temp_var.substr(1), 36
@temp_var: '_' + ordinal.toString(36).replace(/\d/g, 'a')
@variables[@temp_var]: 'var'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment