Skip to content

Instantly share code, notes, and snippets.

@gilesbowkett
Forked from jashkenas/wtf.coffee
Created August 25, 2011 19:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gilesbowkett/1171549 to your computer and use it in GitHub Desktop.
why does this CoffeeScript not accurately translate this Ruby?
insert: (ball, column) ->
for row in @rows when row[column] is null
row[column] = ball
return
def insert(ball, column)
@grid.each do |row|
next unless row[column].nil?
row[column] = ball
return
end
end
it 'avoids "collisions" on insert', ->
@grid = new Grid
@ball = new Ball 1
@ball2 = new Ball 2
@grid.insert @ball, 0
@grid.insert @ball2, 0
expect(@grid.contents(0, 0)).toEqual(@ball)
expect(@grid.contents(0, 1)).toEqual(@ball2)
expect(@grid.contents(0, 2)).toEqual(null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment