Skip to content

Instantly share code, notes, and snippets.

@SiestaMadokaist
Created January 2, 2017 12:24
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 SiestaMadokaist/1cbc87316b9f859d41a79bbe236c058e to your computer and use it in GitHub Desktop.
Save SiestaMadokaist/1cbc87316b9f859d41a79bbe236c058e to your computer and use it in GitHub Desktop.
class LinearEquation
attr_reader(:eq)
extend Memoist
def initialize(&eq)
raise ArgumentError, "equation must be passed" unless block_given?
@eq = eq
end
def raw_equations
@eq
.source
.split("\n")
.map(&:strip)
.select{|x| not x.start_with?("#")}
.slice(1..-2)
end
def equations
raw_equations.map{|s| Equation.new(s) }
end
memoize(:equations)
# ... some others
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment