Ruby with Mac OS X

Hello everyone,

I have a friend that is having some trouble getting a ruby program to
work on her Mac.

I'm kind of wondering if there is anything she can do, I've looked all
over the internet and things, are there any mac users that might be
willing to put in a word of advice?

Thanks.

···

--
Posted via http://www.ruby-forum.com/.

I have a friend that is having some trouble getting a ruby program to
work on her Mac.

I'm kind of wondering if there is anything she can do,

Yep.

are there any mac users that might be willing to put in a word of advice?

Sure, several words: provide some real information about the specific
problem and the environment in which it's happening... :slight_smile:

···

On Jan 18, 2008 8:37 PM, Tj Superfly <nonstickglue@verizon.net> wrote:

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

She can't find the run file.

She's installed "ruby" but it will only open the .rb file in a text
editor.

When she clicks on other (to locate another program) we can't find
anything ruby related.

Does that help?

···

--
Posted via http://www.ruby-forum.com/.

Not really. What program are you trying to run? What version of
Mac OS and Ruby are installed?

···

On Jan 18, 2008 9:25 PM, Tj Superfly <nonstickglue@verizon.net> wrote:

She can't find the run file.

She's installed "ruby" but it will only open the .rb file in a text
editor.

When she clicks on other (to locate another program) we can't find
anything ruby related.

Does that help?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

Hassan Schroeder wrote:

···

On Jan 18, 2008 9:25 PM, Tj Superfly <nonstickglue@verizon.net> wrote:

She can't find the run file.

She's installed "ruby" but it will only open the .rb file in a text
editor.

When she clicks on other (to locate another program) we can't find
anything ruby related.

Does that help?

Not really. What program are you trying to run? What version of
Mac OS and Ruby are installed?

Mac OS 10.5 (leopard)

it said that ruby 1.9.0 is installed

--
Posted via http://www.ruby-forum.com/\.

If you're expecting some zippy IDE, that's not really what Ruby is about. Ruby is a programming language.

Open a terminal window (it's under Applications:Utilities)

Enter some text in a text editor (emacs, vim, vi, ...):

1.upto(3){|n| puts "hello #{n}"}

save it as hello.rb.

type:

ruby hello.rb

results are:

hello 1
hello 2
hello 3

Does this get you started more in the right direction?

···

On Jan 18, 2008, at 9:35 PM, Tj Superfly wrote:

Hassan Schroeder wrote:

On Jan 18, 2008 9:25 PM, Tj Superfly <nonstickglue@verizon.net> >> wrote:

She can't find the run file.

She's installed "ruby" but it will only open the .rb file in a text
editor.

When she clicks on other (to locate another program) we can't find
anything ruby related.

Does that help?

Not really. What program are you trying to run? What version of
Mac OS and Ruby are installed?

Mac OS 10.5 (leopard)

it said that ruby 1.9.0 is installed

Okay, we've got programs running!

Thanks for that.

Now, the program I've created pulls information from a .yaml file. It
works fine on windows, but it says

"Macintosh: ~Xepha$ ruby /users/Xepha/Documents/for-v/numbered_news.rb
/users/Xepha/Documents/for-v/numbered_news.rb:14: uninitialized constant
YAML (NameError)"

So, all the files are in the correct place, there is data inside of the
files, why won't YAML files work?

···

--
Posted via http://www.ruby-forum.com/.

not sure what you are trying to do there..

This might help:

Constants in Ruby
A variable whose name begins with an uppercase letter (A-Z) is a constant. A constant can be reassigned a value after its initialization, but doing so will generate a warning. Every class is a constant.

Trying to substitute the value of a constant or trying to access an uninitialized constant raises the NameError exception.

perhaps you need to read up a little more about Ruby Syntax?

If you send the code for numbered_news.rb I'm sure someone on this list can help..

···

On Jan 19, 2008, at 10:39 AM, Tj Superfly wrote:

Okay, we've got programs running!

Thanks for that.

Now, the program I've created pulls information from a .yaml file. It
works fine on windows, but it says

"Macintosh: ~Xepha$ ruby /users/Xepha/Documents/for-v/numbered_news.rb
/users/Xepha/Documents/for-v/numbered_news.rb:14: uninitialized constant
YAML (NameError)"

So, all the files are in the correct place, there is data inside of the
files, why won't YAML files work?
--
Posted via http://www.ruby-forum.com/\.

I trust you have require "yaml" at the top of the file?

···

On Jan 19, 2008, at 10:39 AM, Tj Superfly wrote:

"Macintosh: ~Xepha$ ruby /users/Xepha/Documents/for-v/numbered_news.rb
/users/Xepha/Documents/for-v/numbered_news.rb:14: uninitialized constant
YAML (NameError)"

Well, I'm using it with arrays, here's a clip of the code that I'm
using.

captions_number = YAML.load(File.open("arrays/captions_number.yaml"))
captions = YAML.load(File.open("arrays/captions_array.yaml"))
captions_delete = []

Basically that clip right there opens the files and sets them for an
array that I use later in the program. I then at the end, send out all
the updates arrays to the files so when it loops back through the array
is updated. This way I can close the program and my arrays are still set
where they were left off.

Like I said it works great in windows, not sure why it's not working
with the Mac.

···

--
Posted via http://www.ruby-forum.com/.

Tj Superfly wrote:

Well, I'm using it with arrays, here's a clip of the code that I'm using.

captions_number = YAML.load(File.open("arrays/captions_number.yaml"))
captions = YAML.load(File.open("arrays/captions_array.yaml"))
captions_delete =

Basically that clip right there opens the files and sets them for an array that I use later in the program. I then at the end, send out all the updates arrays to the files so when it loops back through the array is updated. This way I can close the program and my arrays are still set where they were left off.

Like I said it works great in windows, not sure why it's not working with the Mac.

Ask rather why it's working on Windows. The yaml library is not available by default. You have to require it first. Add this to the top of your script.

require 'yaml'

···

--
RMagick: http://rmagick.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html

require 'yaml'

seems like you may want to back up and do some more reading..

here's a good starting point...
http://en.wikibooks.org/wiki/Ruby_Programming

···

On Jan 19, 2008, at 12:03 PM, Tj Superfly wrote:

Well, I'm using it with arrays, here's a clip of the code that I'm
using.

captions_number = YAML.load(File.open("arrays/captions_number.yaml"))
captions = YAML.load(File.open("arrays/captions_array.yaml"))
captions_delete =

Basically that clip right there opens the files and sets them for an
array that I use later in the program. I then at the end, send out all
the updates arrays to the files so when it loops back through the array
is updated. This way I can close the program and my arrays are still set
where they were left off.

Like I said it works great in windows, not sure why it's not working
with the Mac.
--
Posted via http://www.ruby-forum.com/\.

Okay, we've added that to the mac, and still the same error. I'm going
to post a little bit more of the code, it's 900+ lines long, so i'm
going to only put part of it, the main part of it is repeating for a
different thing.

///////////////// CODE BEGINING /////////////////

$defout.sync=true
attempt = 0
time = Time.now
day = time.wday
year = time.year

require 'uri'
require 'net/http'
require 'FileUtils'
require 'date'
require 'yaml'

# //** Captions Infomation **//
captions_number = YAML.load(File.open("arrays/captions_number.yaml"))
captions = YAML.load(File.open("arrays/captions_array.yaml"))
captions_delete = []

def image_exists?(url_string)
  url = URI.parse(url_string)
  Net::HTTP.start(url.host, url.port) do |http|
  response = http.head(url.path)
  case response
  when Net::HTTPSuccess, Net::HTTPRedirection
    case response.content_type
    when "image/png", "image/gif", "image/jpeg"
        return true
    end
  end
end
  return false
end

def user_wants_to_save?(url)
   print "#{url}"
   puts ""
   #puts "Time: " + time.to_s
   puts "Delete Permanently? [y/N]: "
   input = $stdin.gets
   if /y/i =~ input
     return true
   else
     return false
   end
end

while(attempt >= 0)
  time = Time.now
  attempt += 1
  print "\n", "------------------- ", attempt.to_s, " - ", time.hour,
":", time.min, ":", time.sec, " -------------------", "\n"

       # //** Captions **//
  captions.each do |url|
    if image_exists?(url)
      if user_wants_to_save?(url)
        captions_delete.push url
      end
    end
  end

  captions_delete_number = captions_delete.length
  captions_delete_number -= 1

  while(captions_delete_number >= 0)
    captions.delete(captions_delete[captions_delete_number])
    captions_delete.delete(captions_delete[captions_delete_number])
    captions_delete_number -= 1
  end

  while(captions.length < 8)
    captions_number += 1
    captions.push "http://images.neopets.com/caption/sm_caption_" +
captions_number.to_s + ".gif"
  end

  File.open("arrays/captions_array.yaml","w") do |out|
    out << captions.to_yaml
  end
  File.open("arrays/captions_number.yaml","w") do |out|
    out << captions_number.to_yaml
  end

//////// END OF CODE ////////////

Basically it's a program that checks to see if images exist. =D Now,
with the proper files and everything, it works wonders on windows.
However, even adding the require 'yaml' didn't work. It was there from
the beginning, so that couldn't be the problem - unless you have to have
"yaml" on the mac somewhere?!?

···

--
Posted via http://www.ruby-forum.com/.

Tj Superfly wrote:

Basically it's a program that checks to see if images exist. =D Now, with the proper files and everything, it works wonders on windows. However, even adding the require 'yaml' didn't work. It was there from the beginning, so that couldn't be the problem - unless you have to have "yaml" on the mac somewhere?!?

yaml is part of the standard Ruby installation. When you require "yaml" it defines the YAML constant. If the yaml.rb file doesn't exist for some reason then you would get a LoadError exception. Since you didn't mention such an exception I assume that require "yaml" worked normally and defined the YAML constant.

In mysterious cases like this I find it helps to simplify things a bit. Fire up irb and enter these commands:

require "yaml"
p YAML

The output from the 2nd statement should be YAML. If not, your ruby install is hosed.

I notice from an earlier post that you're running 1.9.0, which is basically a test version of Ruby. OS X 10.5 comes with Ruby 1.8.6 installed, so I'm curious why you're running 1.9.0?

···

--
RMagick: http://rmagick.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html

That works fine, the output was "YAML". From what you said, that's a
good sign.

Now I'm still getting the same error message that I posted above when I
run the program.

"Macintosh: ~Xepha$ ruby /users/Xepha/Documents/for-v/numbered_news.rb
/users/Xepha/Documents/for-v/numbered_news.rb:14: uninitialized constant
YAML (NameError)"

And, turns our 1.9.0 is the current one installed and running; she
didn't know that it was preinstalled on macs. =/ So, yes she is running
1.9.0 now; YAML is "working" just not in the program that I've written.

···

--
Posted via http://www.ruby-forum.com/.

Oh, I forgot to add that I wanted to thank you for working through this
with me and not just telling me to read stuff. I know reading is a great
way to learn, but an even better way is through trial and error, and
these forums have really helped me in the past. =D It's people like you
who really help people like me.

···

--
Posted via http://www.ruby-forum.com/.

Ruby 1.9 isn't preinstalled anywhere, especially not on Macs. The pre-installed version of Ruby on OS X 10.5 is 1.8.6-p111 for example, so if you have a 1.9 then someone installed it manually. And that was a bad idea since 1.9 is a development release.

···

On 19 janv. 08, at 18:43, Tj Superfly wrote:

And, turns our 1.9.0 is the current one installed and running; she
didn't know that it was preinstalled on macs.

--
Luc Heinrich

That's very hard to believe. When did she get this system? Because
as of December when I got a new Mac, it came with 1.8.6.

Open a terminal window and type `ruby -v` and `which ruby` and
see what they output.

···

On Jan 19, 2008 9:43 AM, Tj Superfly <nonstickglue@verizon.net> wrote:

And, turns our 1.9.0 is the current one installed and running; she
didn't know that it was preinstalled on macs.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

Tj--

I would recommend you reduce your program to the smallest number of lines of code that fail around this particular problem. If you still can't see what is causing this, then put the code on http://pastie.caboo.se so everyone can look at it. Remember, looking at your whole program is going to be more confusing than looking at the most trivial reproducible case.

Also, as mentioned, you can eliminate some complexity by simply using Ruby 1.8.6, as shipped with Mac OS X. That way, most people on this list will have the same release. Certainly some are running 1.9, but it is a development release so YMMV.

As a previous poster mentioned, you should ask yourself why it works on Windows. If you type ruby -v on Windows, do you get 1.8.6?

There are a number of things to explore here. Happy spelunking.

···

On Jan 19, 2008, at 9:43 AM, Tj Superfly wrote:

That works fine, the output was "YAML". From what you said, that's a
good sign.

Now I'm still getting the same error message that I posted above when I
run the program.

"Macintosh: ~Xepha$ ruby /users/Xepha/Documents/for-v/numbered_news.rb
/users/Xepha/Documents/for-v/numbered_news.rb:14: uninitialized constant
YAML (NameError)"

And, turns our 1.9.0 is the current one installed and running; she
didn't know that it was preinstalled on macs. =/ So, yes she is running
1.9.0 now; YAML is "working" just not in the program that I've written.

Sorry... your last couple of posts wound up in my spam. If you haven't figured this out yet, here's what I suggest.

$ cd /wherever/your/program/lives
$ irb
>> require 'rubygems'
>> require 'yaml'
>> f = File.open("arrays/captions_number.yaml")
>> f.close
>> my_yaml = File.open("arrays/captions_number.yaml") { |yf| YAML::load(yf) }

At each of these steps you can determine success/failure of the operation. See if this gets you closer.

···

On Jan 19, 2008, at 9:43 AM, Tj Superfly wrote:

That works fine, the output was "YAML". From what you said, that's a
good sign.

Now I'm still getting the same error message that I posted above when I
run the program.

"Macintosh: ~Xepha$ ruby /users/Xepha/Documents/for-v/numbered_news.rb
/users/Xepha/Documents/for-v/numbered_news.rb:14: uninitialized constant
YAML (NameError)"

And, turns our 1.9.0 is the current one installed and running; she
didn't know that it was preinstalled on macs. =/ So, yes she is running
1.9.0 now; YAML is "working" just not in the program that I've written.
--
Posted via http://www.ruby-forum.com/\.