Ruby: Error: Cannot locate this method: String. - ruby

Any idea why certain documentation does not work when using show-doc in pry? E.g. see show-doc with String and Array compared to Set here:
show-doc Set
From: /Users/snowcrash/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/set.rb # line 3:
Class name: Set
Number of lines: 57
--
set.rb - defines the Set class
++
Copyright (c) 2002-2008 Akinori MUSHA <knu#iDaemons.org>
Documentation by Akinori MUSHA and Gavin Sinclair.
All rights reserved. You can redistribute and/or modify it under the same
terms as Ruby.
$Id: set.rb 37839 2012-11-24 18:51:45Z knu $
== Overview
This library provides the Set class, which deals with a collection
show-doc String
Error: Cannot locate this method: String.
[7] pry(main)> show-doc Array
Error: Cannot locate this method: Array.

try installing pry-doc gem:
gem install pry-doc
OR
as per #JayKilleen
if you are using pry in your rails environment you can also try
installing jazz_hands instead github.com/nixme/jazz_hands which brings
pry and other gem functionality into rails console.

String and Array aren't methods, they're classes. That's probably why it's giving you that error there.

String and Array are built-in classes written in C, and you do not have the documentation for them unless you installed them. Set is written in Ruby, and you probably have the documentation as part of the library.

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'

Why could `rb_sysopen` not be found anymore by the custom fact since the upgrade to Puppet4?

The following custom fact:
# returns latest packerversion, e.g. 0.10.1
Facter.add("latest_packerversion") do
setcode do
url="https://www.packer.io/downloads.html"
file = open("#{url}")
contents = file.read()
match = contents.match(/Latest\sversion:\s(.*)</)
match[1]
end
end
worked using puppet 3.6.2, but since the upgrade to 4.5.2 the following issue occurs:
Error: Facter: error while resolving custom fact "latest_packerversion":
No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
Analysis
It seems that the rb_sysopen could not be found anymore for some reason (No such file or directory # rb_sysopen) since the upgrade to Puppet 4.
Puppet4 seems to use an embedded ruby version instead of the one installed on the host (Puppet3):
Puppet 4, both Facter 2.4 and CFacter 0.4, the latest Hiera and
Mcollective, as well Ruby 2.1.5, OpenSSL 1.0.0r, and our gem
dependencies.
Does rb_sysopen not exist in Ruby 2.1.5? No evidence was found.
Perhaps a change related to facts have occurred that could cause the issue? Nothing related was found in the release notes.
Question
Why could rb_sysopen not be found anymore by the custom fact since the upgrade to Puppet4?
Concise
I will include require 'open-uri' in both facts, but I do not understand why this is required since the upgrade to Puppet4
Verbose
Once require 'open-uri' is included in one of the custom facts the issue is solved.
# returns latest gitversion, e.g. 2.8.2
Facter.add("latest_gitversion") do
setcode do
require 'open-uri'
url="https://git-scm.com/downloads"
file = open("#{url}")
contents = file.read()
match = contents.match(/RelNotes.*((\d\.){2}\d)/)
match[1]
end
end
As soon as the require 'open-uri' has been commented out, the issue occurs again:
Error: Facter: error while resolving custom fact "latest_gitversion": No such file or directory # rb_sysopen - https://git-scm.com/downloads
Error: Facter: error while resolving custom fact "latest_packerversion": No such file or directory # rb_sysopen - https://www.packer.io/downloads.html
At the moment it is unclear what is causing the issue.

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 GC module undefined method `malloc_allocated_size`

Trying to use GC module in Ruby 1.9.3
In repl (or script) getting this error
include GC
=> Object
GC.enable
=> false
GC.malloc_allocations
NoMethodError: undefined method `malloc_allocations' for GC:Module
From the 1.9.3 GC Module docs, malloc_allocations is a public class method so why is Ruby saying that it is an undefined method?
The docs are omitting that you need to edit gc.c and set CALC_EXACT_MALLOC_SIZE to 1 before recompiling ruby in order for this method to be available. This flag also turns on the tracking required to support this feature.
See for example https://github.com/ruby/ruby/blob/ruby_1_9_3/gc.c#L3718

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.

Resources