Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Alternatives to sed + awk



On 13 March 2011 08:17, Stephen J. Turnbull <stephen@example.com> wrote:

> Reread what I wrote.  It's not about syntax, it's about semantics.  .sin doesn't
> care whether it lives in Math, String, or Ikebukuro -- its semantics are defined
> without reference to any class.  (OK, I guess it would rather live in
> Ikebukuro.)

I'd rather live in Ikebukuro, too. :)

Math.sin is a proper class method. Let's say you want polar sine and
cosine rather than normal sine and cosine:

Math.polar = true
Math.sin(Math.pi / 4)

The Math class could look something like this:

class Math
  @@polar = false

  def self.polar=(value)
    @@polar = value
  end

  def self.sin(value)
    @@polar ? polar_sine(value) : sine(value)
  end
end


I'd be very surprised if this is actually the way it's implemented in
Ruby, but it certainly *could* be.

--Josh


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links