Module: Amalgam::Models::Attachable::AttachmentExtension
- Defined in:
- lib/amalgam/models/attachable.rb
Defined Under Namespace
Classes: DelegateArray
Instance Method Summary collapse
-
#[](key) ⇒ Object
返回一个 #HashWithIndifferentAccess 包含所有的附件,key为附件的name或者索引, value 为集合, 可直接作为第一个元素调用 举例: page # => [{:name => 'file' , :file =>
}, # => 'file , :file => }, # => 'file2', :file => # => ] page.attachments # => {0 => , 1 => , 2 => ,3 => 'file' => [ , ], 'file2' => [ ] } page.attachments.name #=> page.attachments.first.name.
Instance Method Details
#[](key) ⇒ Object
返回一个 #HashWithIndifferentAccess 包含所有的附件,key为附件的name或者索引, value 为集合, 可直接作为第一个元素调用 举例: page
=> [{:name => 'file' , :file => },
=> 'file , :file => },
=> 'file2', :file =>
=> ]
page.attachments
=> {0 => , 1 => , 2 => ,3 =>
'file' => [<FILE1>,<FILE2>],
'file2' => [<FILE3>]
}
page.attachments.name #=> page.attachments.first.name
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/amalgam/models/attachable.rb', line 37 def [](key) return [key] if = HashWithIndifferentAccess.new each_with_index do |a,i| [i] = a if a.name.present? [a.name] = ([a.name] || DelegateArray.new) << a end end [key] end |