How to pass array as separated arguments to method

This seems close to what I need but it doesn't work for me.

Achieving `call_user_func_array` in Ruby

I have a list as Constant

TYPE = %w(:groups :projects)

I'm using https://github.com/brainspec/enumerize on my RelatedList model which has

enumerize :list_type, in: %w(groups projects), scope: :type

So as per documentation on the github page,

RelatedList.type(:groups) # returns all RelatedList of type 'groups'

However, I want to get all RelatedList contained in my constant TYPE

so I tried

RelatedList.type(TYPE) # doesn't work
RelatedList.send(:type, TYPE) # doesn't work
RelatedList.send(:type, *TYPE) # doesn't work.

RelatedList.type expects a list of separate arguments as symbols but what I have is an array of symbols.

How do I achieve that?


as per DNNX request in answer below, here is the full traceback.

NoMethodError: undefined method `value' for nil:NilClass
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/enumerize-bc01a5cb3c79/lib/enumerize/activerecord.rb:34:in `block (2 levels) in _define_scope_methods!'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/enumerize-bc01a5cb3c79/lib/enumerize/activerecord.rb:34:in `map'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/enumerize-bc01a5cb3c79/lib/enumerize/activerecord.rb:34:in `block in _define_scope_methods!'
    from (irb):2
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus/rails.rb:134:in `console'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:116:in `block in command'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:103:in `fork'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:103:in `command'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:80:in `block (3 levels) in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:80:in `fork'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:80:in `block (2 levels) in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:73:in `each'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:73:in `block in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:62:in `loop'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:62:in `go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (3 levels) in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:78:in `fork'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (2 levels) in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:73:in `each'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:73:in `block in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:62:in `loop'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:62:in `go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (3 levels) in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:78:in `fork'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:78:in `block (2 levels) in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:73:in `each'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:73:in `block in go'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:62:in `loop'
    from /Users/kw/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/zeus-0.13.3/lib/zeus.rb:62:in `go'

Answers


... what I have is an array of symbols

No, is not. This TYPE = %w(:groups :projects) is an array of two strings ':groups' and ':projects', not an array of symbols.

Try this instead:

TYPE = %w(groups projects)
RelatedList.type(*TYPE)

Or, if you is lucky and running your app on Ruby 2.0.0, use symbol array literal:

TYPE = %i(groups projects)
#=> [:groups, :projects]

Need Your Help

telerik editor with iframe

telerik telerik-editor

I'm using Telerik Editor, with following,

Java Date Picker with different calendar system

java swing user-interface calendar datepicker

Is there a J2SE date picker (e.g. JCalendar or JXDatePicker) that be able to use a calendar system other that Gregorian?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.