Arc Forumnew | comments | leaders | submitlogin
2 points by bOR_ 6107 days ago | link | parent

In ruby the lack of a ! at the end of a method isn't a guarantee that a function changes (caught me a few times by surprise). It is just used to distinguish between a state-changing version and nonstate-changing version. The reason for that was to limit the number of !! in your code.

  (+ counter 1)
would have to become

  (+! counter 1)


2 points by lojic 6106 days ago | link

"In ruby the lack of a ! at the end of a method isn't a guarantee that a function changes"

Don't you have that backwards? Typically the ! suffix on a method name in Ruby indicates that the method modifies state.

Also, why would (+ counter 1) have to change to (+! counter 1) ? The former doesn't modify state, it simply returns the sum, right?

-----

1 point by bOR_ 6106 days ago | link

Ugh, as lojic pointed out (thanks for that :)), some sleep-deprived errors in this post. The more correct version:

  In ruby, the lack of a ! at the end of a method isn't a guarantee that a function doesn't modiefy state.
And you're right about (+ counter 1). Blindly remembered the example I got in the ruby forum when I was surprised that some method modified state without a warning !.

The correct example in arc would be this:

  (++ counter 1)
would have to become

  (++! counter 1)

-----