On Thu, Aug 18, 2011 at 10:42 AM, ashbb <ashbbb@gmail.com> wrote:
Green Shoes v1.0 has been released!
--
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
路路路
On Thu, Aug 18, 2011 at 5:17 PM, serialhex <serialhex@gmail.com> wrote:
On Thu, Aug 18, 2011 at 10:42 AM, ashbb <ashbbb@gmail.com> 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
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
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:
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
路路路
Il giorno Tue, 10 Jan 2012 03:26:19 +0900 Matt Mencel <MR-Mencel@wiu.edu> ha scritto:
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.
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
On Mon, Jan 9, 2012 at 7:26 PM, Matt Mencel <MR-Mencel@wiu.edu> wrote:
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
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...
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.
----- Original Message -----
From: "Stefano Crocco" <stefano.crocco@alice.it>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
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 Mencel <MR-Mencel@wiu.edu> ha scritto:
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.
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:
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.
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:
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.
路路路
On Mon, Jan 9, 2012 at 7:46 PM, Stefano Crocco <stefano.crocco@alice.it> wrote:
Il giorno Tue, 10 Jan 2012 03:26:19 +0900 > Matt Mencel <MR-Mencel@wiu.edu> ha scritto:
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 Mencel" <MR-Mencel@wiu.edu>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
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...
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.
----- Original Message -----
From: "Stefano Crocco" <stefano.crocco@alice.it>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
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 Mencel <MR-Mencel@wiu.edu> ha scritto:
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.
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:
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" <jgabrielygalan@gmail.com>
To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
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 Crocco <stefano.crocco@alice.it> wrote:
Il giorno Tue, 10 Jan 2012 03:26:19 +0900 > Matt Mencel <MR-Mencel@wiu.edu> ha scritto:
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.
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:
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.
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.
路路路
On Mon, Jan 9, 2012 at 9:58 PM, Matt Mencel <MR-Mencel@wiu.edu> wrote:
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.