Ruby GC module undefined method `malloc_allocated_size` - ruby

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

Related

xcversion update`: NoMethodError: undefined method `first' for nil:NilClass

When downloading xcode 11 with xcode-install 2.6.1, we get this error
xcversion update: NoMethodError: undefined methodfirst' for nil:NilClass
Its a known issue https://github.com/xcpretty/xcode-install/issues/348
How to fix it?
Works for any ruby version manager (chruby, rvm, rbenv, etc or no version manager)
When you call
xcversion update
Get the path of the failing file -> install.rb
Open it in your editor
Comment line 382
A workaround is to comment out the failing call in install.rb, however its path varies by installation.
Check the output of the xcversion command to find it:
Available session is not valid any more. Continuing with normal login.
/usr/local/lib/ruby/gems/2.4.0/gems/xcode-install-2.4.4/lib/xcode/install.rb:444:in `prereleases': undefined method `first' for nil:NilClass (NoMethodError)
from /usr/local/lib/ruby/gems/2.4.0/gems/xcode-install-2.4.4/lib/xcode/install.rb:379:in `fetch_seedlist'
--> /usr/local/lib/ruby/gems/2.4.0/gems/xcode-install-2.4.4/lib/xcode/install.rb
Open that install.rb in a text editor, go to line #382 which calls the prereleases function and comment it out by changing it to
##xcodes += prereleases.reject { |pre| names.include?(pre.name) }
(Note: this is exactly the same solution as provided by Ted, but without the flashing gifs.)

b.javascript_dialog().exists? is not working for me in WATIR 4.0.2

When I execute the code
b.javascript_dialog().exists?
it works fine in WATIR 3.0.0 but it's throwing the following error in WATIR 4.0.2, Why it is so? Have they given any other function corresponding to "javascript_dialog()"?
hello.rb:8:in <main>': undefined methodjavascript_dialog' for # (NoMethodError)
From the changelog for v3.1.0:
Remove Browser#(javascript_)dialog. Use Browser#alert API instead.
The javascript_dialog has been replaced by alert:
b.alert.exists?

Ruby: Error: Cannot locate this method: String.

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.

before_session hook failed: Pry::CommandError: Cannot locate this method: load

Loading up the Pry REPL in a Ruby script I get this odd error:
before_session hook failed: Pry::CommandError: Cannot locate this method: load.
~/.rvm/gems/ruby-2.0.0-p195/gems/pry-0.9.12.2/lib/pry/method.rb:498:in `pry_doc_info'
(see _pry_.hooks.errors to debug)
Any idea what the problem is?
Notes:
1. The code seems to execute fine other than that cryptic message and
2. I can't find a "_pry_.hooks.errors" file
I encountered this using Ruby 2.4.1 and Pry Stack Explorer, in a Gemfile with:
gem 'pry'
gem 'pry-rescue'
gem 'pry-stack_explorer'
On inserting the Pry Debugger, I saw:
before_session hook failed: Pry::CommandError: Cannot locate this method: load. Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.
/Users/alexharvey/.rvm/gems/ruby-2.4.1/gems/pry-0.11.3/lib/pry/method.rb:489:in `pry_doc_info'
(see _pry_.hooks.errors to debug)
Then I tried following the instructions about pry.hooks.errors:
[2] pry(#<MarkdownLint::Rule>)> puts _pry_.hooks.errors
Cannot locate this method: load. Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.
=> nil
So I just added pry-doc to my Gemfile. Then, I still had another issue. On trying to exit the debugger:
[2] pry(#<MarkdownLint::Rule>)>
when_started hook failed: NameError: uninitialized constant RubyVM::DebugInspector
/Users/alexharvey/.rvm/gems/ruby-2.4.1/gems/binding_of_caller-0.8.0/lib/binding_of_caller/mri2.rb:21:in `callers'
(see _pry_.hooks.errors to debug)
And I found I could solve that one by requesting not the latest version of debug_inspector.
In the end, to successfully use pry and pry-stack_explorer, I ended up with:
gem 'pry'
gem 'pry-rescue'
gem 'pry-stack_explorer'
gem 'pry-doc'
gem 'debug_inspector', '<= 0.0.2'
From the source it looks like the hook possible raised an exception but then swallowed it. The comment above exec_hook recommends that you interrogate $pry_hook_error to find out what happened.
# Execute the specified hook.
# #param [Symbol] name The hook name to execute
# #param [*Object] args The arguments to pass to the hook
# #return [Object, Exception] The return value of the hook or the exception raised
#
# If executing a hook raises an exception, we log that and then continue sucessfully.
# To debug such errors, use the global variable $pry_hook_error, which is set as a
# result.
def exec_hook(name, *args, &block)
e_before = hooks.errors.size
hooks.exec_hook(name, *args, &block).tap do
hooks.errors[e_before..-1].each do |e|
output.puts "#{name} hook failed: #{e.class}: #{e.message}"
output.puts "#{e.backtrace.first}"
output.puts "(see _pry_.hooks.errors to debug)"
end
end
end
I've not been able to reproduce this so please forgive me if this is wildly off base.

Error: undefined method `like' for Sequel:Module

I get this error:
Error: undefined method `like' for Sequel:Module
using:
#info = DB[:info].where(Sequel.like(:content, "%#{params[:sc]}%")) if params[:sc]
I found the example code in Sequel's documentation:
DB[:artists].where(Sequel.like(:name, 'A%'))
What's wrong with my code?
Which version of Sequel are you running? The documentation assumes the latest version, so if you aren't using the latest version, you should upgrade.

Resources