From: Josh Cheek Date: 2013-01-22T07:05:49+09:00 Subject: Re: 2Q: Getting first 4 elements from array and calling class methods directly --f46d042ef4a5b1ab0004d3d3a7c6 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Jan 20, 2013 at 8:08 AM, Panagiotis Atmatzidis wrote: > Hello fellow Rubyists! > > I have written a quick n dirty code to display the first 4 RSS entries > from a feed using "feedzirra" gem. The code is pretty straight forward: > https://gist.github.com/4578863 > > I have two questions, related to this code: > > 1) Is there any more elegant[1] way to get the first for elements of > '@entries' object array? > 2) How should be defined the "feed_list" method in order to be called > like: feed = NewsDisplay::feed_list > > I know I should put a 'self' reference somewhere. A little explanation of > who this technique works would be nice. I know that Class::method calls > might be > deprecated in the future. However even "Class.method" looks much more > elegant and I'd like to know how to implement it. > > Best Regards, > > [1] Elegant = Easy to read, concise code snippet. Cryptic snippets are not > elegant imho. > > Panagiotis (atmosx) Atmatzidis > > email: atma@convalesco.org > URL: http://www.convalesco.org > GnuPG ID: 0xE736C6A0 > gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xE736C6A0 > -- > The wise man said: "Never argue with an idiot. They bring you down to > their level and beat you with experience." > > > > I prefer bracket notation because it works anywhere in an array a = [*'a'..'e'] # => ["a", "b", "c", "d", "e"] # start_index, length a[0, 3] # => ["a", "b", "c"] # start_index..end_index a[0..3] # => ["a", "b", "c", "d"] --f46d042ef4a5b1ab0004d3d3a7c6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sun, Jan 20, 2013 at 8:08 AM, Panagiotis Atmatzidis &l= t;atma@convalesco.= org> wrote:
Hello fellow Rubyists!

I have written a quick n dirty code to display the first 4 RSS entries from= a feed using "feedzirra" gem. The code is pretty straight forwar= d: https://gi= st.github.com/4578863

I have two questions, related to this code:

1) Is there any more elegant[1] way to get the first for elements of '@= entries' object array?
2) How should be defined the "feed_list" method in order to be ca= lled like: feed =3D NewsDisplay::feed_list

I know I should put a 'self' reference somewhere. A little explanat= ion of who this technique works would be nice. I know that Class::method ca= lls might be
deprecated in the future. However even "Class.method" looks much = more elegant and I'd like to know how to implement it.

Best Regards,

[1] Elegant =3D Easy to read, concise code snippet. Cryptic snippets are no= t elegant imho.

Panagiotis (atmosx) Atmatzidis

email: =A0atma@convalesco.org URL: =A0 =A0http://= www.convalesco.org
GnuPG ID: 0xE736C6A0
gpg --keyserver x-hkp://pg= p.mit.edu --recv-keys 0xE736C6A0
--
The wise man said: "Never argue with an idiot. They bring you down to = their level and beat you with experience."





I prefer bracket nota= tion because it works anywhere in an array

a =3D [*'= a'..'e'] # =3D> ["a", "b", "c"= , "d", "e"]

# start_index, length
a[0, 3] # =3D> [&quo= t;a", "b", "c"]

# start_i= ndex..end_index
a[0..3] # =3D> ["a", "b", = "c", "d"]

--f46d042ef4a5b1ab0004d3d3a7c6--