Created
January 2, 2017 12:24
-
-
Save SiestaMadokaist/1cbc87316b9f859d41a79bbe236c058e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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