Stupid typos

Well that took me 10 minutes to figure why setting a new attribute was always showing the same value as what was already set….

old = ent.get_attribute(dict, key, value, nil)	
if (old != value)
  puts "It changed!"
  ent.set_attribute(dict, key, value)
end

Doh! But what is the forth argument to get_attribute?

So the docs say it takes 2 args plus an optional default value…

But it happily consumes 4 arguments. Is that a bug?

1 Like

Yes, it should “normally” return ArgumentError.
But, besides accepting more parameters, it does the original function - as if you only gave 3 parameters.So, I think it’s a bug that doesn’t affect much, however, if you give too many parameters, you confuse yourself.

The doc always said 2 +1 optional parameters -as far as I remember. I wonder where you got the idea that you need a fourth one?

Most likely the method was programmed as get_attribute(dict, key, *args). The “splat” in the third place allows a variable number of subsequent arguments that the method receives as an Array. It can read the first element of the Array and ignore the rest.

2 Likes