Sébastien M. | 1 Dec 2011 01:13
Picon

Re: errors with respond_to? and inject

Nicely done

Discovering ruby and falling in...

Thanks for the reactivity as well

--

-- 
Posted via http://www.ruby-forum.com/.

Sébastien M. | 1 Dec 2011 01:26
Picon

Re: errors with respond_to? and inject

Quick question though

Why don(t u need the 'respond_to?' method
We still have to check if object has a price method in order to return 
nil
if not. Or is there something i missed?

--

-- 
Posted via http://www.ruby-forum.com/.

Josh Cheek | 1 Dec 2011 01:56
Picon
Gravatar

Re: Stupid question

On Wed, Nov 30, 2011 at 2:03 PM, Dave Aronson <rubytalk2dave <at> davearonson.com
> wrote:

> On Wed, Nov 30, 2011 at 14:26, Adam Prescott <adam <at> aprescott.com> wrote:
>
> > You can do it with #chars, too.
>
> Oh yeah!  Good catch!  That knocks four chars (no pun intended) off my
> solution.
>
>
More importantly, it's much clearer.
Josh Cheek | 1 Dec 2011 01:57
Picon
Gravatar

Re: Is high-speed sorting impossible with Ruby?

On Wed, Nov 30, 2011 at 2:00 PM, Gaurav C. <chande.gaurav <at> gmail.com> wrote:

> > What's the difference between Array.new(1e6+1) {|n| ""} and
> > Array.new(1e6+1, "")?
>
> Okay. Thanks all who explained this.
> But, again, why is it better to use the former in this case?
>
> --
> Posted via http://www.ruby-forum.com/.
>
>
As an analogy:

If Jerry, Bob, and sally live in different houses, and you blow Jerry's
house up, then only Jerry is homeless.
If Jerry, Bob, and Sally live in the same house, and you blow Jerry's house
up, then Jerry, Bob, and Sally are all homeless.

As code:

# each get's their own house
houses = Array.new(3) { '' }
houses.first << 'kaboom'
houses # => ["kaboom", "", ""]

# each lives in the same house
houses = Array.new 3, ''
houses.first << 'kaboom'
houses # => ["kaboom", "kaboom", "kaboom"]
(Continue reading)

Garthy D | 1 Dec 2011 02:25
Favicon

Re: Garbage collection and define_finalizer


Hi Robert,

On 30/11/11 23:51, Robert Klemme wrote:
> On Wed, Nov 30, 2011 at 4:11 AM, Garthy D
> <garthy_lmkltybr <at> entropicsoftware.com>  wrote:
>
>> Thankyou for the detailed reply. :)
>
> You're welcome!
>
>> On 30/11/11 00:07, Robert Klemme wrote:
>>>
>>> On Tue, Nov 29, 2011 at 1:43 PM, Garthy D
>>> <garthy_lmkltybr <at> entropicsoftware.com>    wrote:
>
>>> What you observe might mean that you
>>> simply haven't created enough Ruby garbage for GC to think it needs to
>>> work.  I have no idea how you allocate texture memory but if it is in
>>> a C extension written by you I would check whether there is a way to
>>> go through MRI's allocation in order to correct MRI's idea of used
>>> memory.  Implementation of Ruby's String might be a good example for
>>> that.
>>
>> Your assumption re the C extension for texture memory is pretty-much spot
>> on. :)
>
> :-)
>
>> Re texture memory, it's a little more complicated than a standard
(Continue reading)

botp | 1 Dec 2011 02:32
Picon

Re: Stupid question

On Thu, Dec 1, 2011 at 4:03 AM, Dave Aronson
<rubytalk2dave <at> davearonson.com> wrote:
> Can anyone make that even shorter?  Let's play Ruby Golf!  ;-)

can we cheat? :)

> 2011.to_s.chars.sum{|d| d.to_i}
=> 4

Aaron D. Gifford | 1 Dec 2011 03:04
Picon

Re: Stupid question

I Admin Tensor's solution modified to support digit strings up to 1149
characters long (which is the path my muddled brain was meandering
down in my prior post):

irb(main):001:0> s="2011";s.sum%(48*s.size)
=> 4

And to verify worst-case a string of 1149 nine digits:

irb(main):002:0> s="9"*1149;s.sum%(48*s.size)
=> 10341

For longer strings, pass an argument to String#sum bigger than the default 16.

Of course using non-arabic UTF-8 encoded digits makes things very
intersting (a.k.a. fail), a la Devanagari digit six (the first
non-arabic UTF code point for a digit my search turned up):
0x096c.chr(Encoding::UTF_8) a.k.a. "\u096C"

Aaron out.

Admin Tensor | 1 Dec 2011 03:23

Re: Stupid question

Aaron D. Gifford wrote in post #1034519:
>
> irb(main):001:0> s="2011";s.sum%(48*s.size)
> => 4
>
> And to verify worst-case a string of 1149 nine digits:
>
> irb(main):002:0> s="9"*1149;s.sum%(48*s.size)
> => 10341
>
> For longer strings, pass an argument to String#sum bigger than the
> default 16.
>
Very good, Aaron.  Now, is there any way to replace that "s.size" with
something to make it really a one-liner (without the semicolon):
    "some number".sum%(48 times something)
?

Regards,

Bill

--

-- 
Posted via http://www.ruby-forum.com/.

mythpills P. | 1 Dec 2011 07:02
Picon

break from a loop which is run on a xml

how do i loop through a xml and break when i find the node with a
specific value..really struggling to break out of a xml loop..most of
the iterators just loop but cannot be break - ed

please help me with this

for e.g.

this is d code where i find the files in a dir & check d earlier time
stamp for each file which is saved in a xml & do a comparison for each

Find.find('./'){|path|
  if path != './abcd.rb'
    if ! File::directory? ( path )
    modtime = File.mtime(path)
    xmldoc.elements.each("course/file"){ |element|
  oldtime = Time.parse(element.attributes["modified"])
  if modtime > oldtime
        $changed = "yes"
  break
  else
  $changed = "no"
  end
  }
      newfile = course.add_element 'file', {'version'=>'2.0',
'modified'=> modtime, 'download'=>$changed}
      newfile.text = path[2,path.length]
  end
  end
}
(Continue reading)

jake kaiden | 1 Dec 2011 11:47
Picon
Favicon
Gravatar

Re: break from a loop which is run on a xml

hi Mythpills,

  try to reduce your code to an executable snippet and then post that - 
what you've posted above cannot be executed as there are undefined 
variables.

  - j

--

-- 
Posted via http://www.ruby-forum.com/.


Gmane