Skip to content

Instantly share code, notes, and snippets.

@xaviervia
Created November 16, 2011 23:59
Show Gist options
  • Save xaviervia/1371928 to your computer and use it in GitHub Desktop.
Save xaviervia/1371928 to your computer and use it in GitHub Desktop.
Ruby 1.9.3 rvm 1.6.9 Ubuntu 11.10 > May be a bug

In my fast Gem, in lib/fast/fast.rb:

If I write

module Fast
  def self.dir path = nil
    Fast::Dir.new( path ).list if path
    Fast::Dir.new
  end

[...]
end

And I call:

Fast.dir "lib" # And dir exists and have some files

I get a somewhat partial execution of Dir#list

While if I write

module Fast
  def self.dir path = nil
    unless path.nil?
      the_dir = Fast::Dir.new path
      the_dir.list
    else
      Fast::Dir.new
    end
  end

[...]
end

I get a right execution of Fast.dir

(also, if I execute Fast::Dir.new.list "lib" from anywhere else, it works. Specs, foundable in the files, are passing too)

Why? What's the difference? The rest of the code, Fast::Dir and all, is public, https://github.com/xaviervia/fast/tree/fbb9a50d73c9961c0004861a6302a9bfe3b626b3 and this is the version where the problem occurs.

I'm in a Ubuntu 11.10 rvm 1.6.9 ruby 1.9.3

I'm documenting this because the only thing that made it work was a non-relevant code restructuring, without further changes in any method behaviour. I tried everything else. I let this for research later, may be is a bug in Ruby.

@xaviervia
Copy link
Author

I get exactly the same problem in:

module Fast
  def self.file path = nil
    Fast::File.new(path).read if path
    Fast::File.new
  end
end

Versus:

module Fast
  def self.file path = nil
    if path
      Fast::File.new path
      the_file.read
    else
      Fast::File.new
    end  
  end
end

This is looking very much like a bug. Not a very significant one, but sneaky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment