From: Panagiotis Atmatzidis Date: 2013-01-21T01:48:14+09:00 Subject: Re: 2Q: Getting first 4 elements from array and calling class methods directly Thanks, that was an awesome explanation! :-) On 20 Ιαν 2013, at 15:26 , Sandor Szücs wrote: > On 1/20/13 3:08 PM, Panagiotis Atmatzidis wrote: > >> 1) Is there any more elegant[1] way to get the first for elements of '@entries' object array? > > irb:0> a = (1..10).to_a > => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > irb:0> a.take(3) > => [1, 2, 3] > irb:0> a > => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] > irb:0> a.pop(3) > => [8, 9, 10] > irb:0> a > => [1, 2, 3, 4, 5, 6, 7] > irb:0> a.shift(3) > => [1, 2, 3] > irb:0> a > => [4, 5, 6, 7] > >> 2) How should be defined the "feed_list" method in order to be called like: feed = NewsDisplay::feed_list > > 1 class NewsDisplay¬ > 2 def self.feed_list(*args)¬ > 3 new(*args).feed_list¬ > 4 end¬ > 5 def initialize(*args)¬ > 6 end¬ > 7 def feed_list¬ > 8 ['f','e','e','d']¬ > 9 end¬ > 10 end¬ > 11 def test¬ > 12 feed = NewsDisplay::feed_list¬ > 13 end¬ > > irb:0> test > => ["f", "e", "e", "d"] > > > Hth. > -- > All the best, Sandor Szücs > 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."