class SOEClientConfig < SOEConfig
attr_accessor :set, :repository, :installedList
# SOEClientConfig.new(:repository)
def initialize(params=nil)
params ||= {}
@repository = params[:repository]
@set = params[:set]
@installedList = params[:installedList]
end
end
Hence "SOEClientConfig.new" is potentially valid (may use whatever
default values are in initialize).
--
Greg McIntyre
:)
I do defaults like this:
@repository = params[:repository] or "default value"
The only caveat is with booleans.
@is_repository = params[:is_repository] or true # always true, even
if false is passed explicitly
In which case, this might be more appropriate:
@is_repository = if params.key?(:is_repository) then
params[:is_repository] else true end
There might be a more succinct way to do this without resorting to the
? : operator (which I personally avoid for readability reasons).
And as Julio said, document the keys you accept. It makes people who
use your methods smile. ;-)
--
Greg McIntyre
That will work. Just add parentheses. Alternatively, you can use "||"
instead of "or" and avoid needing to use the parentheses altogether.
And by the way, no need for
def foo(bar)
bar ||= {}
end
Just do
def foo(bar = {})
...
end
Again, up to how you like to write your poetry.
Aaah yes. :-)
--
Greg McIntyre