Following along with "Beginning Ruby."

I'm having trouble following along with some of the examples in this
"Beginning Ruby(2nd Edition). I'm at the section where you learn about
I/O handling and tried to do one of the examples and got an error. Not
sure what I did wrong:

irb(main):001:0> File.open("olivertext.txt") do |f|
irb(main):002:1* puts f.gets
irb(main):003:1> end
Errno::ENOENT: No such file or directory - olivertext.txt
        from (irb):1:in `initialize'
        from (irb):1:in `open'
        from (irb):1
        from C:/Ruby193/bin/irb:12:in `<main>'

I tried to use the whole directory to find the file, and got this:

<"C:\Users\Al Baker\Documents\Programming\RuBy olivertext.txt") do |f|
irb(main):005:1* puts f.gets
irb(main):006:1> end
Errno::ENOENT: No such file or directory -
C:UsersAlBakerDocumentsProgrammingRuBy olivertext.txt
        from (irb):4:in `initialize'
        from (irb):4:in `open'
        from (irb):4
        from C:/Ruby193/bin/irb:12:in `<main>'
help!

···

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

try the second with '/' instead of '\' path separator

···

On Thu, Nov 15, 2012 at 1:20 PM, Al Baker <lists@ruby-forum.com> wrote:

I'm having trouble following along with some of the examples in this
"Beginning Ruby(2nd Edition). I'm at the section where you learn about
I/O handling and tried to do one of the examples and got an error. Not
sure what I did wrong:

irb(main):001:0> File.open("olivertext.txt") do |f|
irb(main):002:1* puts f.gets
irb(main):003:1> end
Errno::ENOENT: No such file or directory - olivertext.txt
        from (irb):1:in `initialize'
        from (irb):1:in `open'
        from (irb):1
        from C:/Ruby193/bin/irb:12:in `<main>'

I tried to use the whole directory to find the file, and got this:

<"C:\Users\Al Baker\Documents\Programming\RuBy olivertext.txt") do |f|
irb(main):005:1* puts f.gets
irb(main):006:1> end
Errno::ENOENT: No such file or directory -
C:UsersAlBakerDocumentsProgrammingRuBy olivertext.txt
        from (irb):4:in `initialize'
        from (irb):4:in `open'
        from (irb):4
        from C:/Ruby193/bin/irb:12:in `<main>'
help!

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

Thanks. I wish they could've included that in the book.
I also had problems using the 'Profile' in irb. I used the code in the
book:

require 'profile'
class Calculator
  def self.count_to_large_number
    x = 0
    100000.times {x += 1 }
  end

  def self.count_to_small_number
    x = 0
    1000.times {x += 1 }
  end
end
but only got '100000' and '1000' when I called the methods o for Small
and large number. smh!

···

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

I'm not sure profile gem works in IRB. Have you tried running it from an
.rb file?

···

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

I did. I got:

ruby profiletest.rb

  % cumulative self self total
time seconds seconds calls ms/call ms/call name
  0.00 0.00 0.00 1 0.00 0.00 Class#inherited
  0.00 0.00 0.00 2 0.00 0.00
BasicObject#singleton_method_added
  0.00 0.01 0.00 1 0.00 10.00 #toplevel

Exit code: 0

that's all.

ALSO this code string doesn't really do anything in a text analyzer
script I did.

···

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

I have no clue. Here's the script so far and how it supposed to work:

stopwords = %w{the a by on for are with just but and to the me I has
some in}
lines = File.readlines(ARGV[0])
line_count = lines.size
text = lines.join
total_characters = text.length
total_characters_nospaces = text.gsub(/\s+/,'').length
word_count = text.split.length
sentence_count = text.split(/\.|\?|!/).length
paragraph_count = text.split(/\n\n/).length
all_words = text.scan(/\w+/)
good_words = all_words.select{|word| !stopwords.include?(word)}
good_percentage = ((good_words.length.to_f / all_words.length.to_f)
*100).to_i
sentences = text.gsub(/\s+/, ' ').strip.split(/\.|\?|!/)
sentences_sorted = sentences.sort_by {|sentence| sentence.length}
one_third = sentences_sorted.length/3
ideal_sentences = sentences_sorted.slice(one_third, one_third +1)
ideal_sentneces = ideal_sentences.select {|sentence| sentence =~
/is|are/}

puts "#{line_count} lines"
puts "#{total_characters} characters"
puts "#{total_characters_nospaces} characters (excluding spaces)"
puts "#{word_count} words"
# added Vowels in Text.(This part I added my self!!!! :))
puts "#{text.scan(/[aeiou]/).length} vowels in text."
puts "#{sentence_count} sentences"
puts "#{word_count / sentence_count} words per sentence (average)"
puts "#{paragraph_count} paragraph(s)"
puts "#{sentence_count / paragraph_count} sentences per paragraph
(average)"
puts "#{good_percentage}% of word are non-fluff words"
puts "Summary: \n\n" + ideal_sentences.join(". ")
puts "--End of analysis."

···

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

I tried to delete a directory that I created.

Dir.delete("C:/Users/Al Baker/Documents/Programming/RuBy/NewDir")

and got this:

Errno::EACCES: Permission denied - C:/Users/Al
Baker/Documents/Programming/RuBy/
NewDir
        from (irb):62:in `delete'
        from (irb):62
        from C:/Ruby193/bin/irb:12:in `<main>'

···

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

nvrmnd. i figured it out. thanks again. :slight_smile:

···

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

I'm havng trouble using mysql in my example.

i alreeady did the gem install and copied the "libmysql.dll" over to bin
but still got this:

irb(main):005:0> require 'mysql'
LoadError: cannot load such file -- mysql/mysql_api
        from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require'
        from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require'
        from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mys
ql.rb:6:in `rescue in <top (required)>'
        from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mys
ql.rb:2:in `<top (required)>'
        from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require'
        from
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:i
n `require'
        from (irb):5
        from C:/Ruby193/bin/irb:12:in `<main>'

any ideas?

···

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

Im just a beginer so what is everyone talking about?

···

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

Al Baker wrote in post #1084630:

lines = File.readlines(ARGV[0])

1) Do you know what ARGV contains?
2) What name did you enter for ARGV[0]
3) What is in the file with the name given in 2)?

···

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

Your code works for me when given an argument and a valid text
file. That means the problem is either your argument or your text file.

···

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

Use FileUtils to delete entire folder/directory - Ruby itself will not delete directory if files inside

···

Date: Sat, 17 Nov 2012 14:02:53 +0900
From: lists@ruby-forum.com
Subject: Re: following along with "Beginning Ruby."
To: ruby-talk@ruby-lang.org

I tried to delete a directory that I created.

Dir.delete("C:/Users/Al Baker/Documents/Programming/RuBy/NewDir")

and got this:

Errno::EACCES: Permission denied - C:/Users/Al
Baker/Documents/Programming/RuBy/
NewDir
        from (irb):62:in `delete'
        from (irb):62
        from C:/Ruby193/bin/irb:12:in `<main>'

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

Joey F. wrote in post #1085760:

Im just a beginer so what is everyone talking about?

I'm learning ruby by following along w/ a begnnner's guide to the
language and some of the examples are a bit troublesome is all.

···

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

Alex Mcmillan wrote in post #1084876:

Use FileUtils to delete entire folder/directory - Ruby itself will not
delete directory if files inside

what's the method?

···

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