Ruby Anomaly

For general discussion related FlowStone
Post Reply
User avatar
DaveyBoy
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Ruby Anomaly

Post by DaveyBoy »

Hi Guys

Just noticed the following Ruby anomaly:

Image

.to_a works for a range but not for midi
and
.to_array works for midi but not for a range.

Does anybody know why this is?
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: Ruby Anomaly

Post by RJHollins »

in the first example ... if you use to_b get the same error.

will follow this 8-)
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby Anomaly

Post by tulamide »

RJHollins wrote:if you use to_b get the same error.
There is no #to_b in Ruby

DaveyBoy wrote:.to_a works for a range but not for midi
and
.to_array works for midi but not for a range.

Does anybody know why this is?
Yes, because DSPR did a dirty work while programming the method.

Ruby knows two (and only two) array conversion methods: to_a (explicit conversion) and to_ary (implicit conversion).

When you create your own class, you are encouraged to hook into those. But DSPR ignored it and created a non-ruby-compatible method called to_array. Unfortunately it is confusing (as your post proves) and nothing we can change. We have to live with it, which triggers my perfection OCD. I'm sure, there are more of those language breaking lazy DSPR methods around.
"There lies the dog buried" (German saying translated literally)
User avatar
DaveyBoy
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby Anomaly

Post by DaveyBoy »

thanks for the explanation Tulamide . . I wouldn't have thouight of that.
Talking about OCD, heres a small example of mine:

Image

:D
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby Anomaly

Post by tulamide »

DaveyBoy wrote:Talking about OCD, heres a small example of mine:
:D
OMG! We're brothers in spirit! :lol:
"There lies the dog buried" (German saying translated literally)
Post Reply