What’s the difference between Process.fork and Process.spawn in Ruby 1.9.2

What’s the difference between Process.fork and the new Process.spawn methods in Ruby 1.9.2 Process.fork allows you to run ruby code in another process. Process.spawn allows you to run another program in another process. Basically Process.spawn is like using Process.fork and then calling exec in the forked process, except that it gives you more options. and … Read more

How to specify output file encoding in Ruby?

Here’s an example that outputs a file in the UTF-16LE encoding: open(“data.txt”, “w:UTF-16LE”) Ruby looks at the encoding of the string you are writing, and transcodes as necessary. Here’s a very detailed blog post describing mechanics with excellent examples (see the section called “The Default External and Internal Encodings”).

Ruby – UTF-8 file encoding

No, there are not “exactly 3 ways” to specify the ‘magic comment’ — there are an infinite number of them. Any comment on the first line that contains coding: will work, according to JEG2: … the preferred way to set your source Encoding … it’s called a magic comment. If the first line of your … Read more

What’s the difference between Object and BasicObject in Ruby?

BasicObject was introduced in Ruby 1.9 and it is a parent of Object (thus BasicObject is the parent class of all classes in Ruby). BasicObject has almost no methods on itself: ::new #! #!= #== #__id__ #__send__ #equal? #instance_eval #instance_exec BasicObject can be used for creating object hierarchies independent of Ruby’s object hierarchy, proxy objects … Read more

Ruby 1.9 hash with a dash in a key

There are some legitimate symbols that cannot be used with the new syntax. I cannot find a reference, but it appears that a symbol name matching /^[a-zA-Z_][a-zA-Z_0-9]*[!?]?$/ is allowed with the new syntax. The last character may be the special character “!” or “?”. For any symbol that does not meet these restrictions, you have … Read more

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