[#376274] Best Linux Distro for Ruby? — Nick Hird <boondox@...>

What are some of the better linux distro's for ruby development? I know

15 messages 2011/01/02

[#376329] Is singleton class of an object already created? — Samnang Chhun <samnang.chhun@...>

I would like to know is there any ways to check is singleton class of an

12 messages 2011/01/04

[#376333] Threading in ruby — "Vishnu I." <pathsny@...>

Hi

13 messages 2011/01/04
[#376335] Re: Threading in ruby — Robert Klemme <shortcutter@...> 2011/01/04

On Tue, Jan 4, 2011 at 8:41 AM, Vishnu I. <pathsny@gmail.com> wrote:

[#376339] ripl - an irb alternative - 0.3.0 released — ghorner <gabriel.horner@...>

ripl, a light modular alternative to irb, has reached 0.3.0. ripl

32 messages 2011/01/04

[#376382] Class Initialization? — Kedar Mhaswade <kedar.mhaswade@...>

I have a class and two class methods: self.encode and self.decode. The

14 messages 2011/01/05
[#376385] Re: Class Initialization? — Andrew Wagner <wagner.andrew@...> 2011/01/05

On Wed, Jan 5, 2011 at 9:33 AM, Kedar Mhaswade <kedar.mhaswade@gmail.com>wrote:

[#376388] Petition to add Metasploit Project as Ruby success story — Christian Kirsch <Christian_Kirsch@...7.com>

I noticed the Ruby success stories on the Ruby website. I would like to mak=

10 messages 2011/01/05

[#376453] Block variable - How is it read in English? — SW Engineer <abder.rahman.ali@...>

Following the "Ruby on Rails Tutorial", and under section "6.1.1

16 messages 2011/01/06

[#376574] Best way for Array#find+transform ? — "Jonas Pfenniger (zimbatm)" <jonas@...>

There is a pattern that I'm using quite regularly, but I'm not

17 messages 2011/01/08
[#376575] Re: Best way for Array#find+transform ? — Anurag Priyam <anurag08priyam@...> 2011/01/08

> I know I can come up with a new method on Array that would shorten this t=

[#376576] Re: Best way for Array#find+transform ? — Anurag Priyam <anurag08priyam@...> 2011/01/08

> paths.map{|path| File.join(path, filename)}.select{|name| File.exist?(path)}

[#376577] Re: Best way for Array#find+transform ? — "Jonas Pfenniger (zimbatm)" <jonas@...> 2011/01/09

2011/1/8 Anurag Priyam <anurag08priyam@gmail.com>:

[#376579] Re: Best way for Array#find+transform ? — David J. Hamilton <groups@...> 2011/01/09

Excerpts from Jonas Pfenniger (zimbatm)'s message of Sat Jan 08 16:05:05 -0800 2011:

[#376586] Re: Best way for Array#find+transform ? — "Jonas Pfenniger (zimbatm)" <jonas@...> 2011/01/09

2011/1/9 David J. Hamilton <groups@hjdivad.com>:

[#376606] Re: Best way for Array#find+transform ? — David J. Hamilton <groups@...> 2011/01/10

Excerpts from Jonas Pfenniger (zimbatm)'s message of Sun Jan 09 04:08:10 -0800 2011:

[#376680] Parallel Assignments and Elegance/Complexity Ratio. — Kedar Mhaswade <kedar.mhaswade@...>

In SICP, I read that "Programs should be written for people to read, and

15 messages 2011/01/11
[#376697] Re: Parallel Assignments and Elegance/Complexity Ratio. — Josh Cheek <josh.cheek@...> 2011/01/11

On Tue, Jan 11, 2011 at 8:29 AM, Kedar Mhaswade <kedar.mhaswade@gmail.com>wrote:

[#376682] JRuby 1.6.0.RC1 released — Thomas E Enebo <tom.enebo@...>

The JRuby community is pleased to announce the release of JRuby 1.6.0.RC1.

14 messages 2011/01/11

[#376744] Case statements - Just beautification — flebber <flebber.crue@...>

I just want to clarify case statements the name after the word case is

10 messages 2011/01/12

[#376792] Ruby is interpreted and scripting language? — Sai Babu <sateesh.mca09@...>

I am ruby fresher.

16 messages 2011/01/13

[#376855] Retrieving and copying element from array — Simon Harrison <simon@...>

If I have an array like this:

11 messages 2011/01/13

[#376898] What are your ruby rough cuts ? — "Jonas Pfenniger (zimbatm)" <jonas@...>

Hi rubyists,

32 messages 2011/01/14
[#376930] Re: [poll] What are your ruby rough cuts ? — David Masover <ninja@...> 2011/01/15

On Friday, January 14, 2011 07:34:04 am Jonas Pfenniger (zimbatm) wrote:

[#376937] Re: What are your ruby rough cuts ? — Joseph Lenton <jl235@...> 2011/01/15

David Masover wrote in post #975080:

[#376959] Why Quby? (was Re: What are your ruby rough cuts ?) — David Masover <ninja@...> 2011/01/15

On Saturday, January 15, 2011 04:42:58 am Joseph Lenton wrote:

[#377020] Obscure syntax error — Rolf Timmermans <molfie@...>

Hi all,

16 messages 2011/01/17

[#377052] Calling by Reference - Two Questions — Mike Stephens <rubfor@...>

I know I'm not the first person to get stumped by how to get Ruby to

15 messages 2011/01/18

[#377072] The most recommended way of naming methods in Ruby — Edmond Kachale <edmond.kachale@...>

Rubists,

14 messages 2011/01/18
[#377082] Re: The most recommended way of naming methods in Ruby — Phillip Gawlowski <cmdjackryan@...> 2011/01/18

On Tue, Jan 18, 2011 at 9:16 AM, Edmond Kachale

[#377121] Improving performance of hash math — dblock <dblockdotorg@...>

I am trying to improve performance of Euclidian distance between two

13 messages 2011/01/19

[#377226] Totally lost in learning Ruby — Hilary Bailey <my77elephants@...>

This is my second attempt to understand Ruby. I completely read 1)

61 messages 2011/01/21
[#378239] Re: Totally lost in learning Ruby — Hilary Bailey <my77elephants@...> 2011/02/08

Hi everybody,

[#378246] Re: Totally lost in learning Ruby — Robert Klemme <shortcutter@...> 2011/02/08

On Tue, Feb 8, 2011 at 3:16 AM, Hilary Bailey <my77elephants@gmail.com> wro=

[#377236] using gems installed via 'sudo gem install' — "Piotr S." <thisredoned@...>

I've installed ruby-opengl through sudo gem install because there were

15 messages 2011/01/21

[#377362] pg gem 0.10.1 wth Ruby 1.9.2 does not work with method @pg_conn.exec_prepared(stmt_name, parameters) — Zeno Davatz <zdavatz@...>

Hi

9 messages 2011/01/24

[#377388] The finer points of postfix conditionals. — Jon Leighton <j@...>

Hi,

13 messages 2011/01/24

[#377411] Obtain data from .csv — Kamarulnizam Rahim <niezam54@...>

Sample of .csv file:

19 messages 2011/01/25

[#377609] why is overloading invalid in ruby. — Ted Flethuseo <flethuseo@...>

I don't understand why when I try to overload I get an error. Can I

36 messages 2011/01/27

[#377645] If you had the choice between Ruby & Groovy — Noah Cutler <sit1way@...>

Hey All.

15 messages 2011/01/28

[#377650] IDE? — <johan.tempelman@...>

Hi,

13 messages 2011/01/28

[#377703] Zlib::GzipReader and multiple compressed blobs in a single stream — Jos Backus <jos@...>

Hi,

11 messages 2011/01/28

[#377761] New to programming AND new to Ruby — "Cassandra K." <cassandra.k@...>

Hello. I am trying to teach myself Ruby. I have no background in

13 messages 2011/01/31

[#377785] 2011: Which Ruby books have you read? And which would you recommend? — "Aston J." <azzzz@...>

I know there are a lot of threads about books, but some of them are as

16 messages 2011/01/31

[#377800] How to know the exit status within at_exit() block? — Iñaki Baz Castillo <ibc@...>

Hi, my program invokes "exit true" or "exit false" and I want to catch

17 messages 2011/01/31

Re: Ruby iterative depth.

From: "Abinoam Jr." <abinoam@...>
Date: 2011-01-17 04:23:23 UTC
List: ruby-talk #377001
Hi Marcello,

Sorry, but I was not able to figure out exactly how this piece of code
is trying to generate your desired outcome. (my fault!)
If you're just willing to represent the data in a kind o hierarchical
tree, there's a lot of "Ruby way" to do that.
It seams (in my humble opinion) that you're trying to do it in "C"
way, or something like that.
But, I can give you some tips. See comments in the code.

# You shouldn't need to define methods outside the object scope (like
the one bellow).

# M=E9todos busca em profundidade iterativo
def menu_iterative(menu)
  res =3D []

  # When shifting the first element you're assuming the Array is in a
kind of order,
  # and the first element is the "root". Is this always true?
  el1 =3D menu.shift
  res << el1
  while not menu.empty?
    res_aux =3D []
    for i in menu
      if el1.id =3D=3D i.parent_id
        print el1," =3D=3D ",i,"* ",res_aux.index(el1),"\n"
        res_aux <<  i
	=09
		# The same shift/delete problem here
		# This elemente will never be reevaluated after deleted. And...
		# Using delete here you're assuming that the elements are unique.
		# Is this always true. If there's 2 "i" elements in the Array, with
		# this line you'll be deleting the two of them.
		# You can delete by the index instead.
        el1 =3D menu.delete(i)
	=09
		# This use of retry should be considered deprecated.
		# It seems removed from Ruby 1.9.
        #       retry	=09
	  else
        print el1," !=3D ",i," \n"
      end
    end
    res << res_aux unless res_aux.empty?
    el1 =3D menu.shift
    res << el1
  end
  # You don't need return here, the "return value" is always the last
evaluated expression
  return res
end

Good luck!

On Fri, Jan 14, 2011 at 11:10 PM, Marcello Henrique <faraohh@gmail.com> wro=
te:
> Hi Abinoam,
>
> Thanks for reply, actually the first number is 'id' and second
> 'parent_id', so correct is:
> ["1=3D>0",
> =A0["2=3D>1",
> =A0 =A0["3=3D>2",
> =A0 =A0 =A0["7=3D>3"]
> =A0 =A0],"5=3D>1","6=3D>1"
> =A0],"4=3D>0"
> ]
>
> From source flat:
> [ "1=3D>0","2=3D>1", "3=3D>2","4=3D>0","5=3D>1","6=3D>1","7=3D>3"]
>
> The purpose is to use such as menu like this, based in example above:
> <menu>
> =A0<ul>
> =A0 =A0<li class=3D"sub">"1=3D>0"
> =A0 =A0 =A0<ul>
> =A0 =A0 =A0 =A0<li class=3D"sub">"2=3D>1"
> =A0 =A0 =A0 =A0 =A0<ul>
> =A0 =A0 =A0 =A0 =A0 =A0<li class=3D"sub">"3=3D>2"</li>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0<ul>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<li>"7=3D>3"</li>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0</ul>
> =A0 =A0 =A0 =A0 =A0 =A0</li>
> =A0 =A0 =A0 =A0 =A0</ul>
> =A0 =A0 =A0 =A0</li>
> =A0 =A0 =A0 =A0<li>"5=3D>1"</li>
> =A0 =A0 =A0 =A0<li>"6=3D>1"</li>
> =A0 =A0 =A0</ul>
> =A0 =A0</li>
> =A0 =A0<li>"4=3D>0"</li>
> =A0</ul>
> </menu>
>
> Thanks in advance!
>
> On Fri, Jan 14, 2011 at 21:29, Abinoam Jr. <abinoam@gmail.com> wrote:
>> Hi Marcello,
>>
>> For helping me understand your desired outcome I manually turned it
>> into something more readable (just to read the nesting [] ).
>>
>> ["1=3D>0",["2=3D>1",["3=3D>2",["7=3D>3"]],["3=3D>2"]],["2=3D>1","5=3D>1"=
,"6=3D>1"]]
>>
>> arr[0] =3D "1=3D>0"
>> arr[1] =3D ["2=3D>1", ["3=3D>2", ["7=3D>3"]], ["3=3D>2"]]
>> arr[2] =3D ["2=3D>1", "5=3D>1", "6=3D>1"]
>>
>> Is this what you want?
>>
>> On Fri, Jan 14, 2011 at 11:54 AM, Marcello Henrique <faraohh@gmail.com> =
wrote:
>>> Hello,
>>>
>>> Short question:
>>>
>>> How to make an iterative method of stack?
>>>
>>> Long explanation:
>>> I'm trying to create an iterative method for following structure:
>>>
>>> class Obj
>>> =A0 attr_accessor: id,: parent_id
>>>
>>> =A0 def initialize (id, parent_id)
>>> =A0 =A0 parent_id =3D @ parent_id
>>> =A0 =A0 @ id =3D id
>>> =A0 end
>>>
>>> =A0 def to_s
>>> =A0 =A0 "id: # {@ id}, parent_id: @ # {parent_id} '
>>> =A0 end
>>> end
>>>
>>> left =3D [Obj.new (1.0), Obj.new (2.1), Obj.new (3.2), Obj.new (4.0),
>>> Obj.new (5.1), Obj new (6.1), Obj.new (7.3)]
>>>
>>> My challenge is to make an iterative method, see how far I got:
>>>
>>> def menu_iterative (menu)
>>> =A0 res =3D []
>>>
>>> =A0 el1 =3D menu.shift
>>> =A0 res << el1
>>> =A0 while not menu.empty?
>>> =A0 =A0 res_aux =3D []
>>> =A0 =A0 for i in menu
>>> =A0 =A0 =A0 if el1.id =3D=3D i.parent_id
>>> =A0 =A0 =A0 =A0 print el1, "=3D=3D" i "* ", res_aux.index (el1), "\ n"
>>> =A0 =A0 =A0 =A0 res_aux << i
>>> =A0 =A0 =A0 =A0 el1 =3D menu.delete (i)
>>> =A0 =A0 =A0 =A0 retry
>>> =A0 =A0 =A0 else
>>> =A0 =A0 =A0 =A0 print el1, "! =3D" i, "\ n"
>>> =A0 =A0 =A0 end
>>> =A0 =A0 end
>>> =A0 =A0 res << res_aux unless res_aux.empty?
>>> =A0 =A0 puts
>>> =A0 =A0 el1 =3D menu.shift
>>> =A0 =A0 res << el1
>>> =A0 end
>>> =A0 return res
>>> end
>>>
>>> puts "result:"
>>> pp menu_iterative (left_it)
>>>
>>> I wish the outcome was:
>>>
>>> [*,
>>> =A0[#<Obj:0x7f35b48cab18 @id=3D2, @parent_id=3D1>,
>>> =A0[#<Obj:0x7f35b48caaf0 @id=3D3, @parent_id=3D2>,
>>> =A0 [#<Obj:0x7f35b48caa50 @id=3D7, @parent_id=3D3>]],
>>> =A0[#<Obj:0x7f35b48caaf0 @id=3D3, @parent_id=3D2>]],
>>> =A0[#<Obj:0x7f35b48cab18 @id=3D2, @parent_id=3D1>,
>>> =A0#<Obj:0x7f35b48caaa0 @id=3D5, @parent_id=3D1>,
>>> =A0#<Obj:0x7f35b48caa78 @id=3D6, @parent_id=3D1>]]
>>>
>>> It seems that the problem is attribution without stack, correct?
>>> I'm attaching all I did.
>>>
>>> Thanks for any help.
>>> --
>>> Marcello Henrique
>>> Blog - http://faraohh.wordpress.com
>>> Associa=E7=E3o Software Livre de Goi=E1s (www.aslgo.org.br)
>>> Cercomp - UFG (www.cercomp.ufg.br)
>>>
>>
>>
>
>
>
> --
> Marcello Henrique
> Blog - http://faraohh.wordpress.com
> Associa=E7=E3o Software Livre de Goi=E1s (www.aslgo.org.br)
> Cercomp - UFG (www.cercomp.ufg.br)
>
>

In This Thread