Skip to content

Instantly share code, notes, and snippets.

@spraints
Created June 5, 2009 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spraints/124525 to your computer and use it in GitHub Desktop.
Save spraints/124525 to your computer and use it in GitHub Desktop.
class Thing
# ...
def take(v)
@current_mode.call(v)
@current_mode = Accumulating
end
end
class Accumulating
def self.call(stack, v)
digits = 10**(Math.log10(v).to_i + 1)
x = stack.pop()
x *= digits
x += v
stack.push(x)
end
end
class Replacing
def self.call(stack, v)
stack.pop()
stack.push(v)
end
end
class Inserting
def self.call(stack, v)
top = stack.last
stack.push(top)
stack.push(v)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment