Page 1 of 1

Ruby Anomaly

PostPosted: Wed Nov 13, 2019 12:42 am
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?

Re: Ruby Anomaly

PostPosted: Wed Nov 13, 2019 2:06 am
by RJHollins
in the first example ... if you use to_b get the same error.

will follow this 8-)

Re: Ruby Anomaly

PostPosted: Wed Nov 13, 2019 2:32 am
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.

Re: Ruby Anomaly

PostPosted: Wed Nov 13, 2019 7:31 pm
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

Re: Ruby Anomaly

PostPosted: Thu Nov 14, 2019 2:44 am
by tulamide
DaveyBoy wrote:Talking about OCD, heres a small example of mine:
:D
OMG! We're brothers in spirit! :lol: