Encoding issues with Ruby-2.4.1 - ruby

I am having different output of following line with different version of ruby:
puts "#{"%c"%[254]}"
Output from ruby-2.4.1 : þ
Output from ruby-1.8.7 : �
It looks like issue with encoding, as there is no encoding in Ruby-1.8.7
Can someone please help me to get same result as Ruby-1.8.7 in Ruby-2.4.1 also?
This result is desirable because Ruby-1.8.7 gives me "254" after decoding while Ruby-2.4.1 gives me following error
`%': invalid value for Integer(): "þ" (ArgumentError)

I don't know much about Ruby 1.8.7, as I started Ruby with version 2.3, but this looks promising: https://gist.github.com/afair/2911107
But as everyone else is saying it would be best to upgrade your Ruby version if at all possible. Older versions of Ruby had limited Unicode support.

Related

Ruby bug with fresh install (no implicit conversion of nil into String)

I updated Ruby. When I request Ruby version in CLI, it works, but when I request for the Gem version, it returns the following error:
C:/Ruby23/lib/ruby/2.3.0/rubygems/config_file.rb:90:in `join': no implicit conversion of nil into String (TypeError)
The error is found on a portable version on Windows, as well as on an installed version.
I don't know what to do to run a working version of Ruby. Does anyone already got this bug or have a clue to resolve this?
You need to somehow set the environment variable SYSTEM_CONFIG_PATH
Here's line 90 of rubygems/config_file.rb:
SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH, 'gemrc'
That fails when SYSTEM_CONFIG_PATH is nil.
Searching the exact error message "no implicit conversion of nil into String", I finally found a working solution (may not be the best).
I replace the line 90:
SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH, 'gemrc'
With:
SYSTEM_WIDE_CONFIG_FILE = File.join SYSTEM_CONFIG_PATH.to_s, 'gemrc'

Ruby - ArgumentError: wrong number of arguments (given 3, expected 2)

I am new to Ruby and am attempting to run a program written long ago. I've installed Ruby 2.4.1 and the gem package (test-unit 3.4.3), but when I try to run the following command:
ruby ./run.rb test_5772.rb config_sprint210_uae.rb
Here I am passing two arguments to master ruby script (run.rb). But I am getting an error:
Uncaught exception -- ArgumentError: wrong number of arguments (given 3, expected 2)
from /usr/lib/ruby/2.4.0/optparse.rb:1631:in `permute!'
from /usr/lib/ruby/2.4.0/optparse.rb:1652:in `parse!'
from /home/sadmin/SSN_FWQA/test-framework/lib/testrunner/arguments.rb:279:in `parse'
from ./run.rb:76:in `<main>'
The same code is working fine with Ruby 1.8.7.
This is fixed now, its actually parse method issue because this API is receving arguments (argv) in a hash format but expecting an array.
After making change in this API call, issue has been resolved.

Ruby PDFLib on OSX: LoadError in require

I just downloaded and installed the Ruby for OSX version of PDFLib (from pdflib.com).
I am using the following setup:
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin12.4.0]
OSX Yosemite 10.10.4
PDFLib 9.0.5
The require 'PDFLib' statement in my Ruby file produces the following error message:
/Users/[...]/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require': dlsym(0x7ff6e3ef4b90, Init_PDFLib): symbol not found - [...]/PDFLib.bundle (LoadError)
So it seems that the Ruby interpreter cannot find the Init_PDFLib in the library. But from the output of nm I gather that this symbol seems to be present:
$ nm -g ./PDFlib.bundle | grep -i init
0000000000001200 T _Init_PDFlib
[...]
Has anyone any idea what goes wrong? Thanks in advance for your answers.
Found it!
The PDFlib file is called PDFlib.bundle (small l), and my code did a require 'PDFLib' (capitalized L).
It turns out that the require does load the bundle file regardless of the wrong capitalization, but then searches for the Init_PDFLib symbol, which is not present.
So changing the require statement to require 'PDFlib' (small l) worked.

ruby, rails gem install error - ERROR: While executing gem ... (Encoding::UndefinedConversionError)

I tried with last version with ruby, but when run gem install rails, always got an error
ERROR: While executing gem ... (Encoding::UndefinedConversionError)
U+041D to IBM437 in conversion from UTF-16LE to UTF-8 to IBM437
I am using windows 8.
but gem list ---local working.. only on install, my locale set english.
what kind problem is it?
Use this link:
https://bugs.ruby-lang.org/issues/10300
They said that you need to chance the enconding at The registry.rb file:
Folder: Ruby2.1.0\lib\ruby\2.1.0\win32
File: registry.rb
Line: 70
- LOCALE = Encoding.find(Encoding.locale_charmap)
+ LOCALE = Encoding::UTF_8
+ #LOCALE = Encoding.find(Encoding.locale_charmap)
We'll need more information to solve your problem. What command are you running?
The meaning of the exception is that some character in the gem is invalid in ibm437, a common 'extended ascii' encoding on Windows machines.
You may be to work around the problem by setting your internal encoding to UTF-8. Encoding.default_internal = Encoding::UTF_8
Would you mind adding the output a running a ruby file containing just the following:
p [Encoding.default_external, Encoding.default_internal, __ENCODING__, Encoding.find('filesystem'), Encoding.find('locale')]
Thanks. If you only do it in irb that's fine to.

Error I have gotten a few times and I don't know how to fix it

I keep seeing undefined (?...) sequence: something. For this particular one I had..
/(?<!\d)[0-3]?\d(?!\d)/
but this has happened a few times to me and I'm not sure how to fix it.
These always work in rubular, but then i get that error when I run it?
Help please!
its working here :
rituraj#rituraj:~$ irb
2.1.1 :001 > s = "somestring 23 and 34 and 233"
=> "somestring 23 and 34 and 233"
2.1.1 :002 > s.scan(/(?<!\d)[0-3]?\d(?!\d)/)
=> ["23", "34"]
check your ruby version:
Ruby's regex engine doesn't support lookbehind which is less than 1.9.
You'd need to switch to 1.9+.
optional usage : you can use oniguruma

Resources