I'm currently using AWS cloud 9. I want to run my code but when I use the ruby command to open up my ruby file in irb it sometimes works or it gives me the error message below.
2.6.3 :001 > ruby directory.rb
Traceback (most recent call last):
4: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/irb:23:in `<main>'
3: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/irb:23:in `load'
2: from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
1: from (irb):1
NameError (undefined local variable or method `directory' for main:Object)
Personally, I just drag and drop my .rb file into the cmd window and then press enter. Do you have any reason to want to use the irb?
If you use Atom as a script editor you can install the script package to run your code directly in the app! (File -> Settings -> Packages -> script)
Atom - script
Related
I have some test modifications for the homebrew project but when I try and run them:
$ ruby Homebrew/test/caveats_spec.rb
Traceback (most recent call last):
2: from test/caveats_spec.rb:4:in `<main>'
1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- formula (LoadError)
What gives? I don't see a rakefile either...
Appears the canonical way is via
brew tests which runs all internal tests with the right include path setup.
And to run just one file like tests/caveats_spec.rb (gleaned from brew tests --help)
brew tests --only caveats
Using Ruby 2.6.6 I am not able to open a file the regular way.
2.6.6 :006 > File.open "https://www.pocket-rocket.io/robots.txt"
Traceback (most recent call last):
7: from /Users/martinbraun/.rvm/rubies/ruby-2.6.6/bin/irb:23:in `<main>'
6: from /Users/martinbraun/.rvm/rubies/ruby-2.6.6/bin/irb:23:in `load'
5: from /Users/martinbraun/.rvm/rubies/ruby-2.6.6/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
4: from (irb):6
3: from (irb):6:in `rescue in irb_binding'
2: from (irb):6:in `open'
1: from (irb):6:in `initialize'
Errno::ENOENT (No such file or directory # rb_sysopen - https://www.pocket-rocket.io/robots.txt)
The file exists and I am able to browse to it using my browser.
But I keep getting this error.
I tried:
require 'open-uri'
no success.
What am I doing wrong here? Is it a possible problem with this Ruby version?
I could not find any hints.
File.open expects files to be on the disk, it doesn't work with remote files.
Instead you could do use Net::HTTP.get, which will return a string.
url = URI('https://www.pocket-rocket.io/robots.txt')
Net::HTTP.get(url) # => "User-agent: *\nDisallow: /wp-admin/\nAllow: /wp-admin/admin-ajax.php\n"
I am trying to use calabash-android to start a test sever on a phone in android studio. I am new to this and gotten this far thanks to tutorials.
I downloaded java, ruby, calabash-android, set-up environment variables, created a key store in the .calabash-settings, have a .debug-keystore file in my .android folder.
I am stuck as to what this problem is I can run bundle exec calabash-android resign app-debug.apk fine but when i do bundle exec calabash-android run app-debug.apk, I get the following error message. I am obviously missing something but i am unsure what:
C:\Users\Dell\AndroidStudioProjects\Calabash>bundle exec calabash-android build app-debug.apk
WARNING: skipped META-INF/CERT.RSA as unsafe
Traceback (most recent call last):
8: from C:/Ruby26-x64/bin/calabash-android:23:in `<main>'
7: from C:/Ruby26-x64/bin/calabash-android:23:in `load'
6: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/calabash-android-0.5.14/bin/calabash-android:76:in `<top (required)>'
5: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/calabash-android-0.5.14/bin/calabash-android-build.rb:2:in `calabash_build'
4: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/calabash-android-0.5.14/lib/calabash-android/helpers.rb:162:in `fingerprint_from_apk'
3: from C:/Ruby26-x64/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
2: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/calabash-android-0.5.14/lib/calabash-android/helpers.rb:163:in `block in fingerprint_from_apk'
1: from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/calabash-android-0.5.14/lib/calabash-android/helpers.rb:163:in `chdir'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/calabash-android-0.5.14/lib/calabash-android/helpers.rb:177:in `block (2 levels) in fingerprint_from_apk': **No signature files found in META-INF. Cannot proceed. (RuntimeError)**
I encountered the same issue with latest available versions of ruby (v3.0.2p107) and calabash (v0.9.22).
I avoided the issue by using "bundle install" command and specifying a GemFile with previous versions.
# Contents of Gemfile
source "https://rubygems.org"
ruby "2.5.1"
gem 'calabash-android', '0.9.5'
gem 'cucumber'
gem 'rexml'
gem 'rubyzip', '1.2.1'
You may want to refer to similar issues raised such as https://github.com/calabash/calabash-android/issues/802
I'm currently trying to create a basic GUI application in Ruby using the Tk module. Whenever I attempt to require the module (as tk or tcltklib), I get the following LoadError:
LoadError (126: The specified module could not be found. - C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tcltklib.so)
Currently, I have:
Installed Tcl (ActiveTcl) from the ActiveState website, specifically the 8.5.18.0 version for Windows (x86).
Installed Ruby with RubyInstaller for Windows, specifically Ruby+Devkit 2.5.3-1 (x86). The MSYS2 development toolchain was also selected to be installed, and all 3 components were chosen during ridk install.
Run gem install tk. The RubyInstaller changelog notes that, as of version 2.4.1-1, tk is no longer part of the standard library but can still be installed with gem install tk.
Attempted to require 'tk' and require 'tcltklib' in IRB and received the error above.
When running the following through IRB
require 'tk'
The output is
Traceback (most recent call last):
8: from C:/Ruby25/bin/irb:11:in `<main>'
7: from (irb):3
6: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:39:in `require'
5: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
4: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:135:in `require'
3: from C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tk.rb:7:in `<top (required)>'
2: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
1: from C:/Ruby25/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
LoadError (126: The specified module could not be found. - C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tcltklib.so)
The referenced file (C:/Ruby25/lib/ruby/gems/2.5.0/gems/tk-0.2.0/lib/tcltklib.so) does in fact exist though and this error seems different to the one output when requiring a non-existent module.
There seems to be very little information on this specific error, in fact, the only related things I could find were 10 year old posts on the Ruby forum which didn't yield much information.
I'm trying to run a ruby script in the mac automator. First of all, I chosen "Run Shell script" and in the drop down for that I choose /bin/zsh instead of /usr/bin/ruby, beacuse I want to run ruby 2.3.0 and not whatever version there was in /usr/bin/ruby.
/Users/me/.rvm/rubies/ruby-2.3.0/bin/ruby /Users/me/Projects/Private/SubSeeker/main.rb $1
This is how the automator script looks like, and it runs well till that point I have to require something. For example when I require rest-client, I do it like this: require 'rest-client' but for some reason that doesn't work. I get this error:
/Users/me/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- rest-client (LoadError)
from /Users/me/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/me/Projects/Private/SubSeeker/scraper.rb:1:in `<top (required)>'
from /Users/me/Projects/Private/SubSeeker/main.rb:4:in `require_relative'
from /Users/me/Projects/Private/SubSeeker/main.rb:4:in `<main>'
The gem is installed and I can use the script when not running through automator.
Any idea what I'm doing wrong here?