Hi - I was expecting the handling to be more along the lines of
":required is a new value in the hash".

I'll probably stick to a validation that requires presence, until I
work out when a hash is in use and when it isn't :)

To be honest, I never even thought of scale and precision as being
named options in a Hash. They usually get treated in tutorials as just
a list of stuff you add to the end of a declaration, like :default
and :null. More reading, then. :)

Newbies, eh? How do you go about working this out? I mean, I started
(for migrations) with documents like 
http://guides.rubyonerails.org/migrations.html
- there's no hint there of a named option hash. Just a lot of things
that can get appended to a declaration. There's not even a reference
to some other resource that provides more detail, is there? Even stuff
like 
http://api.rubyonrails.org/classes/ActiveRecord.ConnectionAdapaters/TableDefinition.htl
doesn't mention that the :scale and :precision have to come last
because they are in a named option hash.

Thanks for the detailed help and explanation! I'm now both wiser and
more confused, at the same time. What document set have I missed
reading that would let me know that :decimal has a named option hash?
I'm clearly missing something quite important.

Cheers, JeremyC.

On Jan 3, 12:01 pm, Tomoaki Hayasaka <[email protected]>
wrote:
> <<EOS
> Field declaration is handled by method_missing(), that means the
> declaration must be a valid Ruby method call.
>
> Remember that Ruby has a parser feature that you can omit braces if
> the last argument of a method call is a Hash.  Rails and Hobo use
> that feature for "named options".
> EOS
>
> def enum_string(*args)
>   "type enum_string #{args.inspect}"
> end
>
> def decl(type, *args)
>   puts "@@@ decl(): type = #{type}"
>   options = args.extract_options!
>   args.each_with_index { |val, i| puts "  args[#{i}] = #{val.inspect}" }
>   options.each { |key, val| puts "  options[#{key.inspect}] = #{val.inspect}" 
> }
> end
>
> # decl :decimal, :scale => 1, :precision => 3, :required   # 1. syntax error, 
> unexpected '\n', expecting tASSOC
> decl :decimal, { :scale => 1, :precision => 3 }, :required # 2. no syntax 
> error, but won't work as expected
> decl :decimal, :required, { :scale => 1, :precision => 3 } # 3. works
> decl :decimal, :required, :scale => 1, :precision => 3     # 4. works, same 
> as 3.
> decl enum_string(:first, :second, :third), :required, {}   # 5. works
> decl enum_string(:first, :second, :third), :required       # 6. works, same 
> as 5.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to