Skip to content

Instantly share code, notes, and snippets.

@stmtk1
Created June 16, 2019 13:42
Show Gist options
  • Save stmtk1/fa41e320d70fbcb90665cde2c98c420f to your computer and use it in GitHub Desktop.
Save stmtk1/fa41e320d70fbcb90665cde2c98c420f to your computer and use it in GitHub Desktop.
class Peano
def self.method_num
instance_methods(false)
.map{ |a| a.to_s}
.filter{ |a| /\Anum\d+\Z/ =~ a }
.size
end
def self.increment
num = self.method_num + 1
define_method("num#{num}"){ nil }
end
def self.decrement
num = self.method_num
remove_method("num#{num}")
end
end
class Tape
def initalize
@head = Class.new(Peano)
@@next_class = nil
@@prev_class = nil
end
def increment
@head.increment
self
end
def decrement
@head.decrement
self
end
def next_tape
if @@next_class.nil?
@@next_class = Tape.new
@@next_class.prev_class = self
end
@@next_class
end
def prev_tape
if @@prev_class.nil?
@@prev_class = Tape.new
@@prev_class.next_class = self
end
@@prev_class
end
end
Tape.new.next_tape.prev_tape.prev_tape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment