Erwin
2010-Dec-25 15:23 UTC
I sit possible to write it in one line ? Array init + Array loading
I am always writing it in 2 lines : ( Array init then loading the array ) @providers = [] @authentications.map {|authentification| @providers << authentification.provider } Is there any Ruby writing for writing just one line ? thanks fyh -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2010-Dec-25 15:35 UTC
Re: I sit possible to write it in one line ? Array init + Array loading
On 25 December 2010 15:23, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> wrote:> I am always writing it in 2 lines : ( Array init then loading the > array ) > > @providers = [] > -0T7WJtAfHdtXkx7Hs9IJweEvbiji2Gh8@public.gmane.org {|authentification| @providers << > authentification.provider } > > Is there any Ruby writing for writing just one line ?@providers = @authentications.map { |authentication| authentication.provider } -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
ivanpoval
2010-Dec-26 09:22 UTC
Re: I sit possible to write it in one line ? Array init + Array loading
With ActiveSupport from Rails it''s also possible: @providers = @authentications.map(&:provider) -- Thanks, Ivan Povalyukhin On Dec 25, 7:35 am, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 25 December 2010 15:23, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > I am always writing it in 2 lines : ( Array init then loading the > > array ) > > > @providers = [] > > -0T7WJtAfHdtXkx7Hs9IJweEvbiji2Gh8@public.gmane.org {|authentification| @providers << > > authentification.provider } > > > Is there any Ruby writing for writing just one line ? > > @providers = @authentications.map { |authentication| > authentication.provider }-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-26 14:30 UTC
Re: I sit possible to write it in one line Array init + Array loading
ivanpoval wrote in post #970734:> With ActiveSupport from Rails it''s also possible: > @providers = @authentications.map(&:provider)However, this is slightly slower, so while I use it in tests, I tend not to use it in application code.> -- > Thanks, Ivan PovalyukhinBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Dec-26 14:35 UTC
Re: I sit possible to write it in one line ? Array init + Array loading
On Dec 26, 9:22 am, ivanpoval <ivanpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> With ActiveSupport from Rails it''s also possible: > @providers = @authentications.map(&:provider)As of ruby 1.8.7 it''s built into ruby (no active support required) Fred> -- > Thanks, Ivan Povalyukhin > > On Dec 25, 7:35 am, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 25 December 2010 15:23, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > I am always writing it in 2 lines : ( Array init then loading the > > > array ) > > > > @providers = [] > > > -0T7WJtAfHdtXkx7Hs9IJweEvbiji2Gh8@public.gmane.org {|authentification| @providers << > > > authentification.provider } > > > > Is there any Ruby writing for writing just one line ? > > > @providers = @authentications.map { |authentication| > > authentication.provider }-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2010-Dec-26 17:30 UTC
Re: Re: I sit possible to write it in one line Array init + Array loading
On 26 December 2010 14:30, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> ivanpoval wrote in post #970734: >> With ActiveSupport from Rails it''s also possible: >> @providers = @authentications.map(&:provider) > > However, this is slightly slower, so while I use it in tests, I tend not > to use it in application code.But it''s much faster to type, and easy to read.... you''re not prematurely optimising, are you? ;-) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-26 20:51 UTC
Re: I sit possible to write it in one line Array init + Array loading
Frederick Cheung wrote in post #970761:> On Dec 26, 9:22am, ivanpoval <ivanpo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> With ActiveSupport from Rails it''s also possible: >> @providers = @authentications.map(&:provider) > > As of ruby 1.8.7 it''s built into ruby (no active support required)1.8.7? I thought it didn''t make it in until later. Good to know.> > FredBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-26 20:52 UTC
Re: Re: I sit possible to write it in one line Array init + Array loading
Michael Pavling wrote in post #970778:> On 26 December 2010 14:30, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >> ivanpoval wrote in post #970734: >>> With ActiveSupport from Rails it''s also possible: >>> @providers = @authentications.map(&:provider) >> >> However, this is slightly slower, so while I use it in tests, I tend not >> to use it in application code. > > But it''s much faster to type, and easy to read.... you''re not > prematurely optimising, are you? ;-)When a premature optimization is this simple, and this free of disadvantages, there''s no reason not do to it. Any more complex and I wouldn''t. :) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.