I'm working on a class Chartand a parameter marginthat contains the values of :top, :bottom, :rightand :left. My first option was to make a marginsetter and set these values:
chart.margins = {:left => 10, :right => 15}
This is good, because it is clearly a setter, but when I think it over, I think this can also be misleading: the user might think that the fields contain only values :leftand :rightthat is not so. Another option is to exclude =and make it the usual way:
chart.margins(:left => 10, :right => 15)
Using this syntax is easy to understand what is happening, but it is not a standard network device and conflicts with marginsgetter. And there is another option:
chart.margins(:left, 10)
chart.margins(:right, 15)
I don’t know what to think about it. It’s obvious to me that the method is a setter, but this time I can’t set multiple values with just one call, and the getter problem again. I'm relatively new to Ruby, and I'm not used to all the idioms yet. So what do you guys think? Which of the best options?
source
share