I'm trying to require hiredis in irb and it's already sending me an error:
irb(main):001:0> require "hiredis"
WARNING: could not load hiredis extension, using (slower) pure Ruby implementation.
=> true
irb(main):002:0>
Upon further investigation, I notice that it's crashing at this part of the code.
# hiredis-rb/lib/hiredis/connection.rb
module Hiredis
begin
require "hiredis/ext/connection"
Connection = Ext::Connection
rescue LoadError
warn "WARNING: could not load hiredis extension, using (slower) pure Ruby implementation."
require "hiredis/ruby/connection"
Connection = Ruby::Connection
end
end
So, I required the file hiredis/ext/connection and the error I get is the following error:
irb(main):001:0> require "hiredis/ext/connection"
LoadError: /home/***/projects/***/.gemset/extensions/x86_64-linux/2.1.0-static/hiredis-0.5.2/hiredis/ext/hiredis_ext.so:
undefined symbol: redisReaderFree -
/home/***/projects/***/.gemset/extensions/x86_64-linux/2.1.0-static/hiredis-0.5.2/hiredis/ext/hiredis_ext.so
from /home/***/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I'm using Ubuntu and latest stable version of Redis (2.8.18). How do I fix this? Thanks!
EDIT:
So after looking at the hiredis-rb page: https://github.com/redis/hiredis-rb, it says that I should do the following:
To use hiredis with redis-rb, you need to require
redis/connection/hiredis before creating a new connection.
So I did a require "redis/connection/hiredis" on irb and then require "hiredis" and everything worked fine, no more warnings.
But now the warnings don't happen at all anymore now. I assumed that I'd need to require "redis/connection/hiredis" everytime for it to work but now it just works. So I dunno why it's not warning me anymore now. I thought calling require "redis/connection/hiredis" during that irb session was only for that session, not all succeeding sessions.
Related
i start to learn ruby and scraping and i try to open an url with open and i got
lib/scrapper.rb:7:in `initialize': No such file or directory # rb_sysopen - https://en.wikipedia.org/wiki/Douglas_Adams (Errno::ENOENT) from lib/scrapper.rb:7:in `open' from lib/scrapper.rb:7:in `<main>'
And this is my code :
# frozen_string_literal: true
require 'rubygems'
require 'open-uri'
require 'nokogiri'
document = open("https://en.wikipedia.org/wiki/Douglas_Adams")
puts document
After some long hours of google research i don't find any solution ðŸ˜
I test open with this url to : http://www.krosmoz.com/fr/almanax
thanks all 🧅
ps i'm on mac m1 don't know if they are compatibility issues
The problem is likely that you are using ruby 3.0.0.
Under Ruby 2.7, I receive the following warning:
warning: calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open
And under Ruby 3.0, it has been removed.
So the solution, per the warning:
document = URI.open("https://en.wikipedia.org/wiki/Douglas_Adams").read
I require a native extension, that is in my filesystem but not compatible with my current system. In this case I want to react in ruby and use a mock implementation, but this code
begin
require 'dotstar'
rescue LoadError
puts "Got LoadError"
require 'dotstarsimulator'
rescue
puts "Warning: could not open dotstar native support => using sim"
require 'dotstarsimulator'
end
simply crashes without calling my rescue code.
Same for an irb session, in which I just try to require 'dotstar'.
Looks like this is a duplicate of: How do I rescue from a `require': no such file to load in ruby?
You have to specifically resque LoadError
I'm trying to write a Ruby plasmoid for KDE. I need to use barely one rubygem. Whenever I write require 'dbus', it throw me and an error:
code/main.rb:6:in 'require': no such file to load -- dbus (LoadError)
code/main.rb:6:in '<module:TestApp>'
code/main.rb:5:in '<top (required)>'
/usr/share/apps/plasma_scriptengine_ruby/applet.rb:177:in 'load'
/usr/share/apps/plasma_scriptengine_ruby/applet.rb:177:in 'init'
/usr/share/apps/plasma_scriptengine_ruby/applet.rb:201:in 'constraintsEvent': undefined method 'constraintsEvent' for nil:NilClass (NoMethodError)
/usr/share/apps/plasma_scriptengine_ruby/applet.rb:201:in 'constraintsEvent': undefined method 'constraintsEvent' for nil:NilClass (NoMethodError)
Actually, normal "ruby main.rb" works well (regarding on "require" part), but testing plasmoid with "plasmoidviewer" fails. Note, that regular gems from standart Ruby installation works well, i.e. require 'Qt4' or require 'yaml' loads perfectly. I'm using Ruby 1.9.2p180 under Linux.
09:40 PM - UPDATE: Richard Dale, one of the QtRuby developers, just fixed this issue a few minutes ago. Next release of KDE will have patched version of QtRuby.
require 'find'
require 'findUtils'
Find.find(PATH_WHERE_GEM_IS_INSTALLED) do |path|
if FileTest.directory?(path)
$: << File.expand_path(path)
if File.basename(path)[0] == ?. and File.basename(path) != '.'
Find.prune
else
next
end
else
end
end
and after that you can do
require 'dbus'
Have you tried this:
require 'rubygems'
?
I am experiencing issues when I am trying to run my .rb-file with the Ruby-command trying to access a gem. The gem i am trying to use is Ruby-Whois. I have an example script below that when I try to execute it through "ruby whois.rb" I get this error message:
./whois.rb:6: uninitialized constant Whois (NameError)
However, if I run the same script line by line in IRB I get the expected result. What may cause this?
Below is whois.rb
require "rubygems"
require "whois"
domain = "google.com"
c = Whois::Client.new
a = c.query(domain)
puts a
change the name of your file - there is ambiguity in require 'whois' and ruby is requireing your file instead of a gem. when you do it line by line in irb ruby knows what you exactly want to require, so everything works.
In my Ruby program, I'm trying to lazy-load a library (crack for the curious).
If I do this:
require 'rubygems'
require 'crack'
Everything is working fine. However, when I try this:
require 'rubygems'
autoload :Crack, 'crack'
A LoadError is raised. (no such file to load -- crack)
Why is this error being raised? Is it because 'crack' (and therefore my other user-installed gems) are not in my $LOAD_PATH?
edit:
Furthermore, autoload does work with the Standard Library:
autoload :Yaml, 'yaml'
works fine, and raises no errors.
You'll need to add the 'crack' gem to your $LOAD_PATH by doing:
gem 'crack'
This is necessary because RubyGems replaces Kernel#require with a method that attempts to "activate" the gem before requiring it if necessary, but doesn't do the same thing for Kernel#load - and autoload calls load on the backend.