Green Shoes v1.0 released

Hello, everyone.

Green Shoes v1.0 has been released!

Install: gem install green_shoes

RubyGems: green_shoes | RubyGems.org | your community gem host

GitHub: GitHub - ashbb/green_shoes: Green Shoes is one of the colorful Shoes written in pure Ruby.

Manual: http://ashbb.github.com/green_shoes

ML: http://librelist.com/browser/shoes

Green Shoes is one of the colorful Shoes[1], written in pure Ruby with
Ruby/GTK2.

Let’s celebrate Whyday 2011[2] with Green Shoes!! :smiley:

ashbb

1: http://shoesrb.com/
2: Shopify Engineering

On Thu, Aug 18, 2011 at 10:42 AM, ashbb [email protected] wrote:

Green Shoes v1.0 has been released!

YAY!!! shoooes rocks!!
hex


my blog is cooler than yours: serialhex.github.com

The wise man said: “Never argue with an idiot. They bring you down to
their
level and beat you with experience.”

Other than the fact Linux has a cool name, could someone explain why I
should use Linux over BSD?

No. That’s it. The cool name, that is. We worked very hard on
creating a name that would appeal to the majority of people, and it
certainly paid off: thousands of people are using linux just to be able
to say “OS/2? Hah. I’ve got Linux. What a cool name”. 386BSD made the
mistake of putting a lot of numbers and weird abbreviations into the
name, and is scaring away a lot of people just because it sounds too
technical.
– Linus Torvalds’ follow-up to a question about Linux

Amazing work!
Shoes is the best GUI micro toolkit.
Congratz :slight_smile:

why do I get this error?

C:\Users\aaa\Ruby193>gem install green_shoes
ERROR: Error installing green_shoes:
invalid gem format for C:/Users/aaa/Ruby193/lib/ruby/gems/1.9.1/cache/g
lib2-1.1.0-x86-mingw32.gem

Shoes is the best GUI micro toolkit.

amen, brother…

Congratz :slight_smile:

indeed - nice work ashbb!

  • j

Hi,

I have this class (below) that takes a deeply nested hash and returns
back a new hash without all the nesting. The problem I’m having is that
it seems to be that @all_values is not empty if I call it a second time
from my program. First time is fine, but the next time I use
get_all_values_nested, @all_values still has the results in it from the
first time it was used.

Any thoughts on what I’m doing wrong? I just want @path and @all_values
to be empty each time I use the get_all_values_nested function.

Thanks,
Matt

class Tools

@path = []
@all_values = {}

def self.get_all_values_nested(nested_hash={})
puts “ALL VALS: #{@all_values}”
nested_hash.each_pair do |k,v|
@path << k
case v
when Array, DateTime, FalseClass, Fixnum, NilClass, String,
TrueClass then
@all_values.merge!({"#{@path.join(".")}" => “#{v}”})
@path.pop
when Hash then get_all_values_nested(v)
else raise ArgumentError, “Unhandled type #{v.class}”
end
end
@path.pop

return @all_values

end

end

Il giorno Tue, 10 Jan 2012 03:26:19 +0900
Matt M. [email protected] ha scritto:

be empty each time I use the get_all_values_nested function.
By definition, instance variables (including instance variables of class
objects) keep their values until something else is assigned to them. If
you
need to access the values stored in @path and @all_values from somewhere
other than gel_all_values_nested, but you want them empty in that
method,
then you’ll have to do so yourself:

class Tools

def self.get_all_values_nested nested_hash = {}
@path = []
@all_values = {}
# …
end

end

If those two variables are only needed from within the body of
get_all_values_nested, then you should use local variables instead.

I hope this helps

Stefano

Tried that, and it works to point except I lose the pertinent @path data
I need. So if the vars are outside the method then the returned hash
looks like this…

{
“department.org_unit_id.id” => “6830”,
“department.name” => “Art”,
“department.code” => “08”,
“department.path” => “/content/Art”
}

…if I put the vars inside the method I lose the identifying path
information…

{
“id” => “6830”,
“name” => “Art”,
“code” => “08”,
“path” => “/content/Art”
}

A conundrum…

In case you are curious, I’m using this in a ruby gem I created to
interface with Desire2Learn SOAP stuff. I use the Savon gem to grab the
SOAP responses…and the responses are nested hashes…and I
sometimes need to know the nested path into the hash value I’m looking
for.

https://github.com/chewie71/ruby-d2l

Matt

----- Original Message -----
From: “Stefano C.” [email protected]
To: “ruby-talk ML” [email protected]
Sent: Monday, January 9, 2012 12:46:24 PM
Subject: Re: Class instance variable question

Il giorno Tue, 10 Jan 2012 03:26:19 +0900
Matt M. [email protected] ha scritto:

be empty each time I use the get_all_values_nested function.
By definition, instance variables (including instance variables of class
objects) keep their values until something else is assigned to them. If
you
need to access the values stored in @path and @all_values from somewhere
other than gel_all_values_nested, but you want them empty in that
method,
then you’ll have to do so yourself:

class Tools

def self.get_all_values_nested nested_hash = {}
@path = []
@all_values = {}
# …
end

end

If those two variables are only needed from within the body of
get_all_values_nested, then you should use local variables instead.

I hope this helps

Stefano

On Mon, Jan 9, 2012 at 7:26 PM, Matt M. [email protected] wrote:

case v
end

end

Instance variables keep their value after the method execution, that’s
why you are seeing that problem.
Instead of using an instance variable you could just use the return
value of the recursive call to merge it to a local variable that you
then return. This way you won’t need instance variables at all:

require ‘date’

class Tools
def self.get_all_values_nested(nested_hash={}, path=[])
all_values = {}
nested_hash.each_pair do |k,v|
path << k
case v
when Array, DateTime, FalseClass, Fixnum, NilClass, String,
TrueClass then
all_values.merge!({“#{path.join(”.“)}” => “#{v}”})
when Hash then
all_values.merge!(get_all_values_nested(v, path))
else
raise ArgumentError, “Unhandled type #{v.class}”
end
path.pop
end
return all_values
end
end

p Tools.get_all_values_nested({“a” => 1, “b” => {:first => “1”}})
p Tools.get_all_values_nested({“a” => {“first_level” => 42, “nested”
=> {“key” => “value”}}, “b” => {:first => “1”}})

$ ruby nested_hash.rb
{“a”=>“1”, “b.first”=>“1”}
{“a.first_level”=>“42”, “a.nested.key”=>“value”, “b.first”=>“1”}

Does this help?

Jesus.

Possible workaround. Since @path is popped clean each time it’s used I
think I can leave that outside the method and put @all_values inside the
method. It’s an ugly hack but I think it works for now until I figure
out a better way to do it.

Definitely open to suggestions.

Thanks,
Matt

----- Original Message -----
From: “Matt M.” [email protected]
To: “ruby-talk ML” [email protected]
Sent: Monday, January 9, 2012 1:38:15 PM
Subject: Re: Class instance variable question

Tried that, and it works to point except I lose the pertinent @path data
I need. So if the vars are outside the method then the returned hash
looks like this…

{
“department.org_unit_id.id” => “6830”,
“department.name” => “Art”,
“department.code” => “08”,
“department.path” => “/content/Art”
}

…if I put the vars inside the method I lose the identifying path
information…

{
“id” => “6830”,
“name” => “Art”,
“code” => “08”,
“path” => “/content/Art”
}

A conundrum…

In case you are curious, I’m using this in a ruby gem I created to
interface with Desire2Learn SOAP stuff. I use the Savon gem to grab the
SOAP responses…and the responses are nested hashes…and I
sometimes need to know the nested path into the hash value I’m looking
for.

https://github.com/chewie71/ruby-d2l

Matt

----- Original Message -----
From: “Stefano C.” [email protected]
To: “ruby-talk ML” [email protected]
Sent: Monday, January 9, 2012 12:46:24 PM
Subject: Re: Class instance variable question

Il giorno Tue, 10 Jan 2012 03:26:19 +0900
Matt M. [email protected] ha scritto:

be empty each time I use the get_all_values_nested function.
By definition, instance variables (including instance variables of class
objects) keep their values until something else is assigned to them. If
you
need to access the values stored in @path and @all_values from somewhere
other than gel_all_values_nested, but you want them empty in that
method,
then you’ll have to do so yourself:

class Tools

def self.get_all_values_nested nested_hash = {}
@path = []
@all_values = {}
# …
end

end

If those two variables are only needed from within the body of
get_all_values_nested, then you should use local variables instead.

I hope this helps

Stefano

On Mon, Jan 9, 2012 at 7:46 PM, Stefano C. [email protected]
wrote:

first time it was used.
class Tools

def self.get_all_values_nested nested_hash = {}
@path = []
@all_values = {}

end

end

The problem there is that you lose the aggregation of path within the
recursive calls, since you are clearing at the beggining of each call.

If those two variables are only needed from within the body of
get_all_values_nested, then you should use local variables instead.

That’s what I thought. If this is not the case, then the solution
should be different, but I’m not sure how those two requirements hold
up together: you need them empty before calling that method, but need
to read the resulting values in other cases. Also, I think path ends
up empty after the call, so maybe we are talking only about
all_values. If this is the case I would do it like this:

class Tools
def self.get_all_values_nested(nested_hash={})
@all_values = _get_all_values_nested(nested_hash)
end
end

and use the definition for _get_all_values_nested that I propose in my
other email. The OP should clarify, but I don’t think his use case
involves having memory of the computation within calls or something
like that.

Jesus.

Hi Jesus,

I tried your suggestion…

class Tools

def self.get_all_values_nested(nested_hash={})
@all_values = _get_all_values_nested(nested_hash)
end

def self._get_all_values_nested(nested_hash={}, path=[])
all_values = {}
nested_hash.each_pair do |k,v|
path << k
case v
when Array, DateTime, FalseClass, Fixnum, NilClass, String,
TrueClass then
all_values.merge!({“#{path.join(”.“)}” => “#{v}”})
when Hash then
all_values.merge!(_get_all_values_nested(v, path))
else
raise ArgumentError, “Unhandled type #{v.class}”
end
path.pop
end
return all_values
end

end

…and it seems to work nicely. The all_values hash is cleared each
time, but values in path are sent in each time the
_get_all_values_nested is recursively called. I’ll see how it goes with
further testing.

Thanks!

Matt

----- Original Message -----
From: “Jesús Gabriel y Galán” [email protected]
To: “ruby-talk ML” [email protected]
Sent: Monday, January 9, 2012 2:14:37 PM
Subject: Re: Class instance variable question

On Mon, Jan 9, 2012 at 7:46 PM, Stefano C. [email protected]
wrote:

first time it was used.
class Tools

def self.get_all_values_nested nested_hash = {}
@path = []
@all_values = {}

end

end

The problem there is that you lose the aggregation of path within the
recursive calls, since you are clearing at the beggining of each call.

If those two variables are only needed from within the body of
get_all_values_nested, then you should use local variables instead.

That’s what I thought. If this is not the case, then the solution
should be different, but I’m not sure how those two requirements hold
up together: you need them empty before calling that method, but need
to read the resulting values in other cases. Also, I think path ends
up empty after the call, so maybe we are talking only about
all_values. If this is the case I would do it like this:

class Tools
def self.get_all_values_nested(nested_hash={})
@all_values = _get_all_values_nested(nested_hash)
end
end

and use the definition for _get_all_values_nested that I propose in my
other email. The OP should clarify, but I don’t think his use case
involves having memory of the computation within calls or something
like that.

Jesus.

Hi Barry,

why do I get this error?

C:\Users\aaa\Ruby193>gem install green_shoes
ERROR: Error installing green_shoes:
invalid gem format for > C:/Users/aaa/Ruby193/lib/ruby/gems/1.9.1/cache/g
lib2-1.1.0-x86-mingw32.gem

Umm,… I don’t know why…
I googled with the term ‘invalid gem format’.
Many people are saying that why not remove the gems and reinstall them
again.

ashbb

On Mon, Jan 9, 2012 at 9:58 PM, Matt M. [email protected] wrote:

 raise ArgumentError, "Unhandled type #{v.class}"

end
path.pop
end
return all_values
end

end

…and it seems to work nicely. The all_values hash is cleared each time, but
values in path are sent in each time the _get_all_values_nested is recursively
called. I’ll see how it goes with further testing.

But, do you really need a class instance variable holding the result
of a call? If not, please considering droping the instance variable
stuff altogether.

On the other hand, I don’t understand what you are saying here, sorry.
What do you mean by “values in path are sent in”? Also the “but” in
front of that sentence seems to imply that something is wrong?
In each iteration through the hash entries, path contains the all keys
that lead nested hash through nested hash to the current key under
inspection. If the key is a hash, the path gets passed to the
recursive call, so that in that recursive call, each key has the
previous path at the start of the array and can append to the end of
the array each current key.

Jesus.

gem install -u green_shoes ? Just a wild guess, but might work.

2012/1/9, Barry Yu [email protected]: