Is there any way to make a Ruby temporary file permanent?

Not really. For the question itself, see this: ObjectSpace.undefine_finalizer(tmpfile) The Tempfile library uses Ruby ObjectSpace finalizers to automatically delete itself on garbage collection. By using the above line you can remove the Tempfile’s ability to delete itself if you don’t delete it. So, for example: $ irb 2.0.0p0 :001 > require “tempfile” => true 2.0.0p0 … Read more

What is the preferred way (better style) to name a namespace in Ruby? Singular or Plural?

Use: module FooLib end module FooLib::Plugins end class FooLib::Plugins::Plugin; end #the base for plugins class FooLib::Plugins::Bar < FooLib::Plugins::Plugin; end class FooLib::Plugins::Bar2 < FooLib::Plugins::Plugin; end or in a different words: module FooLib module Plugins class Plugin; end #the base for plugins class Bar < Plugin; end class Bar2 < Plugin; end end end Also arrange the … Read more

How to dynamically create a local variable?

You cannot dynamically create local variables in Ruby 1.9+ (you could in Ruby 1.8 via eval): eval ‘foo = “bar”‘ foo # NameError: undefined local variable or method `foo’ for main:Object They can be used within the eval-ed code itself, though: eval ‘foo = “bar”; foo + “baz”‘ #=> “barbaz” Ruby 2.1 added local_variable_set, but … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)