ruby on rails - Add Methods to Iterated Objects -


i have block looks similar one:

    <% @github_tmp_files.files.each |file| %>       <li><%= link_to @github_tmp_files.filename(file.key), @github_tmp_files.download_url(file.key) %></li>     <% end %> 

as can see in loop call 2 methods file argument:

@github_tmp_files.filename(file.key) @github_tmp_files.download_url(file.key) 

i prefer call 2 methods that:

file.filename (should return) @github_tmp_files.filename(file.key) file.download_url (should return) @github_tmp_files.download_url(file.key) 

so @ end can write loop this:

     <% @github_tmp_files.files.each |file| %>       <li><%= link_to file.filename, file.download_url %></li>     <% end %> 

how have change files method in @github_tmp_files, allows behaviour? thanks

#in @github_tmp_files -> class  def files    github_bucket.objects(prefix: @folder) end 

just out of curiosity:

<% @github_tmp_files.files.map(&:key).each |file| %>   <li>     <%= link_to *[:filename, :download_url].each |m|                    @github_tmp_files.public_send(m, file)                 end %>   </li> <% end %> 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -