7 Replies - 2017 Views - Last Post: 03 October 2011 - 01:39 PM Rate Topic: -----

#1 jb1drv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 18-April 11

Starting Ruby

Posted 12 September 2011 - 02:02 AM

I was wondering where to start learning ruby. So far I have done the tryruby.org tutorial, & I am reading OReilly.The.Ruby.Programming.Lang, Agile Web Development with rail, browsing http://ruby-doc.org, and trying out things on irb. I've went through the 2 easiest tutorials.
I was also wondering how to drop multiples while looping...
 
d = [7, 6, 5, 4, 3, 2, 1]
d.find_all {|i| i % 3 == 0 }



Is This A Good Question/Topic? 0
  • +

Replies To: Starting Ruby

#2 Skaggles  Icon User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 251
  • View blog
  • Posts: 640
  • Joined: 01-March 09

Re: Starting Ruby

Posted 12 September 2011 - 02:55 AM

There's not much more that can be said as far as resources that aren't covered in the Ruby (and Rails) Resources thread. I'd suggest checking out Learning Ruby the Hard Way.

As for your question about dropping multiples, you can try a each loop:

d.each do |i|
    d.delete(i) if i % 3 == 0
end


Was This Post Helpful? 0
  • +
  • -

#3 xclite  Icon User is offline

  • LIKE A BOSS
  • member icon


Reputation: 902
  • View blog
  • Posts: 3,163
  • Joined: 12-May 09

Re: Starting Ruby

Posted 12 September 2011 - 07:02 AM

It's generally not a good idea to modify a collection you are iterating over - in fact, it's more idiomatic to pass a block as the OP did than to loop to delete these multiples. Another option would be:
d = d.reject{|num| num % 3 == 0}


Or
d.reject! {|num| num % 3 == 0}


Was This Post Helpful? 3
  • +
  • -

#4 jb1drv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 18-April 11

Re: Starting Ruby

Posted 13 September 2011 - 03:41 AM

Thanks. I am sorry I meant to remove by every 3rd position. More importantly though how do I keep my output open after typing up my code in Notepad++ or SciTE, so I don't have to always use irb.
Was This Post Helpful? 0
  • +
  • -

#5 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Starting Ruby

Posted 14 September 2011 - 10:59 PM

View Postjb1drv, on 13 September 2011 - 03:41 AM, said:

More importantly though how do I keep my output open after typing up my code in Notepad++ or SciTE, so I don't have to always use irb.


You're looking for a ruby IDE I take it? Something where you can just click a "play" button and have your code run and produce output? I'm still on the lookout for a good IDE to use with ruby... I had a somewhat good, somewhat TERRIBLE experience with net beans. They dropped support for ruby just recently which is a complete shame so you need to install version 7.x or something like that.

I think maybe Aptana could be a good one (I have so much trouble setting these types of things up though, it's prohibiting my Ruby learning).

I just did a fresh format, so maybe I can get Aptana to do a ruby project really quick here...


Guide (Windows...)

Installation
1) Install git for version control, Ruby for.. you know, Rubying, and Aptana for writing your code and running it all in the same interface.

Install msysgit (A version control thingy which integrates with aptana)

Install Ruby installer (Let's you have ruby installed on windows if you haven't already done this)
IMPORTANT! Make sure you install support for ruby tk. It's an option of some kind in the installer.

Install aptana

Hello World on Aptana: Ruby
2)  Open Aptana
     File -> New -> Ruby Project
                     Name:  Hello
                     Radio: "i'll generate my own code"
                     Button =>  "Finish"

3)  Click on tab, "Project Explorer" (on left)

4)  Right click "Hello" (should be an Icon of a folder)
     New -> File
             File Name:  hello.rb
             Button => "Finish"

5)  Type in your hello world code
# BEGIN ACTUAL CODE
language = "Ruby"
puts "Hello World of Aptana: " + language
# END ACTUAL CODE

6)  Click green play button (top bar)



At the bottom of the screen you should see

Quote

Hello World of Aptana: Ruby


That should be a pretty good start. I can't garatee that Aptana is actually a good IDE because I only have experience with netbeans, which was like... kinda cool (and I think more powerful) but also really frustrating for me for some reason.

Let me know if I've gone wrong somewhere in my instructions.

This post has been edited by NotarySojac: 14 September 2011 - 11:13 PM

Was This Post Helpful? 0
  • +
  • -

#6 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Starting Ruby

Posted 14 September 2011 - 11:41 PM

Ok, for sleep points, I wrote this too

require 'tk'   # does this throw an error?  Then figure out how to install tk somehow.  Then we'll make windows and stuff!

language = "Ruby"
puts "Hello World of Aptana: " + language



def save_a_baby_in_a_rickety_old_stroller(amnt=0)  # now what could this be for?
  baby = 0
  stroller = 100
  
  baby = baby + amnt
  
  world = stroller / baby
  
  puts world
end


root = TkRoot.new() { title "Hello, world!" }  # Title a new window, yes we definately need a root


label = TkLabel.new() { text "" }   # Let's add a completely empty, boring label
label.pack("side"=>"left")

label.text = "TO"  # Ok, it can say "TO" but this is quite random in my opinion




button = TkButton.new(root) {     # hmmm, now let's splash in a button
  text "First, rightmost"         # and it will have text
  command do                                                  # and there will be an action!
      save_a_baby_in_a_rickety_old_stroller(1)              
      label.text = "SAVED!"
  end            
  }

 # but where shall we place this strange new button?  And how long...

button.pack("side"=>"right", "fill"=>"y")        # We'll put it to the right, and let it stretch out along it's lovely y axis


Tk.mainloop()   # OK, show the window!  WOOH-POW!!!




Instead of commenting my code, a narrated what was going on in my head when I read my code. I think this style of coding is the next big thing! If it doesn't work out for you, you can also reference the intellectual property at this address.
Was This Post Helpful? 0
  • +
  • -

#7 jb1drv  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 18-April 11

Re: Starting Ruby

Posted 16 September 2011 - 06:35 AM

hold on.

This post has been edited by jb1drv: 16 September 2011 - 06:39 AM

Was This Post Helpful? 1
  • +
  • -

#8 Redalin  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 23
  • Joined: 02-October 11

Re: Starting Ruby

Posted 03 October 2011 - 01:39 PM

View PostNotarySojac, on 15 September 2011 - 12:59 AM, said:

You're looking for a ruby IDE I take it? Something where you can just click a "play" button and have your code run and produce output? I'm still on the lookout for a good IDE to use with ruby... I had a somewhat good, somewhat TERRIBLE experience with net beans. They dropped support for ruby just recently which is a complete shame so you need to install version 7.x or something like that.

I think maybe Aptana could be a good one (I have so much trouble setting these types of things up though, it's prohibiting my Ruby learning).





We are using Eclipse to learn Ruby in my class. I'm new to an programming so I don't know the capabilities of the IDE, but Eclipse seems Okay. I downloaded RubyMine, but it seems like a major jump from Eclipse. But, more experienced programmers may say otherwise.


Eclipse: http://www.eclipse.org/
Install Ruby in Eclipse:
Help > Install New Software.
Use DLTK Updates - http://download.ecli...y/dltk/updates/
Expand DLTK 2.0 menu, select Core Frameworks, Core Frameworks SDK, Ruby Development Tools and Ruby Development Tools SDK. Click Next and follow screens.
Once installed, change to the Ruby Perspective by: Window > Open Perspective > Select Other, Select Ruby.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1