• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:06
CEST 15:06
KST 22:06
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 1 - Final Week6[ASL19] Finals Recap: Standing Tall12HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0
Community News
Esports World Cup 2025 - Brackets Revealed10Weekly Cups (July 7-13): Classic continues to roll4Team TLMC #5 - Submission extension3Firefly given lifetime ban by ESIC following match-fixing investigation17$25,000 Streamerzone StarCraft Pro Series announced7
StarCraft 2
General
The GOAT ranking of GOAT rankings RSL Revival patreon money discussion thread Who will win EWC 2025? Weekly Cups (July 7-13): Classic continues to roll Esports World Cup 2025 - Brackets Revealed
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event $5,100+ SEL Season 2 Championship (SC: Evo) WardiTV Mondays Sparkling Tuna Cup - Weekly Open Tournament
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
External Content
Mutation # 482 Wheel of Misfortune Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome
Brood War
General
Flash Announces (and Retracts) Hiatus From ASL BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Starcraft in widescreen A cwal.gg Extension - Easily keep track of anyone
Tourneys
[Megathread] Daily Proleagues Cosmonarchy Pro Showmatches CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile Nintendo Switch Thread Stormgate/Frost Giant Megathread CCLP - Command & Conquer League Project The PlayStation 5
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Future of Porn US Politics Mega-thread Russo-Ukrainian War Thread Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2025!
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023 2024 - 2025 Football Thread NBA General Discussion NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Men Take Risks, Women Win Ga…
TrAiDoS
momentary artworks from des…
tankgirl
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 619 users

Beginning Programming: Ruby style

Blogs > Anacletus
Post a Reply
Anacletus
Profile Blog Joined April 2012
United States733 Posts
Last Edited: 2012-05-15 20:10:01
May 15 2012 01:57 GMT
#1
This blog is being written to try and help those who have no programming experience jump head first into it.




A little bit about me


I'm a fairly new programming student myself. I have most of my experience in programming in C++ and Ruby, although I have dabbled in many other languages. I've done many of the programming challenges on projecteuler and InterviewStreet and would recommend both of those sites to people who are looking for some programming challenges (links below). So back to my point, because I am a newbie too what I say may not necessarily be the best way to do something, hell, it may even be one of the worst. That doesn't detract from my overall goal of getting some of you guys immersed in programming.
  • http://projecteuler.net/
  • https://www.interviewstreet.com/challenges/




Programs that you will be using


This section explains the material that you should download. I'll try and explain the steps to set all of this up the best that I can.

To start off you need to install Ruby itself. I recommend doing that here: http://rubyinstaller.org/downloads/

You need to click the link labeled "Ruby 1.9.3-p194" on that page as this is the most recent version of Ruby without all of the extra stuff attached.

Once you've finished installing Ruby open up your command prompt. Now we are going to install your IDE aka Integrated Development Environment which is where you are going to be writing your code.

In your commend prompt type the following line "gem install redcar" this will install redcar.

Now that you have installed redcar you can run it. You can do this two ways - you can use search to find redcar and click to run it (it should be a batch file within your Ruby folder, doing this can let you create yourself a neat little icon for redcar) or you can run it through command prompt. Simply type "redcar" into command prompt to run it.

For any more questions you could have about installation, here are a couple of links you can look over for additional information:
  • http://www.ruby-lang.org/en/downloads/
  • https://github.com/redcar/redcar/wiki/installation


Awesome! You have just set up your own IDE for Ruby and you're ready to code!



Your first program!

So, you should have redcar opened and your screen should look something like this:

+ Show Spoiler +
[image loading]


What you want to do now should seem fairly obvious - but go ahead and create a new file.

To precursor your first program I'd like to throw a few things out there for those who may have some prior programming experience - Ruby is an interpreted language so for this simple stuff we will not be using any 'Require' statements (equivalent of include in C).

So to start off really simple, type into redcar the following:

+ Show Spoiler +
puts "hello"


Now to test this go over to the drop-down bar and under plug-ins select execute. You will see another tab pop up and this is your build log. It should simply say "hello" in it. Congratulations, your code ran successfully!

Another way to test your code is to run it through command prompt. This is a bit more time consuming though. So let's say you want to do this, first you want to save your file. I'm going to save mine in my Ruby folder - labeled Ruby193.

The next step is to set command prompt to run from that folder, so you use the code cd to change the destination and then type the folder destination after that. So once you find where you've saved your program find it's destination and type something similar to my example below:

+ Show Spoiler +
cd C:\Ruby193


Awesome, command prompt is now able to run from this folder, now you want to actually run your program, to do that type:

+ Show Spoiler +
ruby hello.rb


Simply replace hello.rb with whatever you saved your program as and you will see your program run right in front of you.

Congratulations! You've just created and ran your first Ruby program!



Getting your hands dirty

Now let's move onto some of the more juicy things, shall we?

In Ruby there are no types - everything is an object. This basically means that unlike most other languages when you are declaring variables you don't need to assign them. In other languages if you wanted to create a new variable that is an integer you would do something like this:

+ Show Spoiler +
int x = 0 ;


However in Ruby, you don't need to do that, you only have to type this:

+ Show Spoiler +
x = 0


It's a bit simpler, and having no type casting has it's advantages and it's disadvantages, but we'll worry about that later.

For now let's do some simple addition and experiment with types.

type the following into redcar:

+ Show Spoiler +

x = 4
y = 5

z = x + y

puts z


So, yeah. Run that and you should get an output of "9". What you've just done is created three variables, x, y, and z. You'll notice that they are integers. Now try this:

+ Show Spoiler +

x = 4
y = 5.0

z = x + y

puts z


This may not mean much to you, but those are actually two different types of variables! adding a decimal place to the y value actually makes it a float type and the fact that they add together is super cool - I'm bringing this up because I'd like to preface how awesome Ruby is with the flexibility it has with variables.

Next I'll have you guys play around with strings a little bit, try typing this in:

+ Show Spoiler +

x = "Bat"
y = "man"

z = x + y

puts z


Ruby has MANY awesome abilities to manipulate strings in cool ways. Since everything is an object in Ruby these are called methods - here try this method out real quick:

+ Show Spoiler +

x = "Bat"
y = "man"

z = x + y
puts z.reverse


Now to move onto showing some examples of arrays and iterations done in Ruby. Type the following into redcar:

+ Show Spoiler +

x = [2, 5, 6]

x.each do
puts x
end


Your result should be:

+ Show Spoiler +

2
5
6
2
5
6
2
5
6


Notice that it repeated the numbers 2, 5, 6 three times. This is because it ran the loop three times - once for each item within the array, x. When using puts if you put in the variable name it will spit out all of the information and that can be annoying. What if you only want to output each of the values in the array once?

+ Show Spoiler +

x = [2, 5, 6]

x.each do |n|
puts n
end


Your output should be:

+ Show Spoiler +

2
5
6


Now, you should notice that the first code segment is pretty different from the second. To begin with, what's that |n|? That is a new variable that is assigned the value of the variable at the position of the loop that you are in. This may sound confusing (due to my bad wording) but it basically means that as your code runs through the loop it becomes the value of the variable in that position in the loop. So as it runs through each value within x it becomes the value of that position. Then you put n out there and it outputs each value in x.

That was pretty neat if I do say so myself! Anyway, this was just something short I thought I'd prepare to have you mess around a bit before I release you out into the vast world of Ruby.



Additional repositories

I hope you're interested as I have prepared a few awesome links below to further your learning!

  • http://ruby-doc.org/
    + Show Spoiler +
    This will be your best friend for finding out more syntax and reserved words in Ruby. Take a gander into the 'Core' section at the top of this page to find the entire Ruby source code at your disposal. If you're looking for something neat to mess around with I suggest taking a look in the 'String' section within 'Core' to find some fun methods to play around with in Ruby.

  • http://tryruby.org/levels/1/challenges/0
    + Show Spoiler +
    This is a pretty well written hands-on tutorial to help you really get the basics of Ruby down. I highly recommend that you do it!

  • http://www.sapphiresteel.com/ruby-programming/The-Book-Of-Ruby
    + Show Spoiler +
    This is an entire FREE online book that you can download in PDF that is incredibly descriptive and will cover everything you will need to know about Ruby. It has amazing details and examples so you can gets some hands-on experience as to what is being talked about and the writer is extremely entertaining as well.

  • http://pragprog.com/book/ltp2/learn-to-program
    + Show Spoiler +
    This is a book that I have not personally read - but I assume it must be great! This source was supplied from: http://www.teamliquid.net/blogs/viewblog.php?topic_id=337732#7






Closing thoughts


I know my first hands on examples didn't cover base on a lot of things (please don't hunt me down for not mentioning classes in an object-only language) - I was mostly trying to show off some programming fundamentals and be able to help people execute their own program instead of teaching them programming fundamentals (that is what the links are for).

I am also sure that there are other wizards out there who know much more than I who would be glad to extend upon any of the points that I've made and also might even drop by and throw in some tid bits that could be included in the OP. If you're one of those wizards who think that I have left something important out feel free to PM me and I'll be glad to include it - also feel free to toss it down in a comment if that suits your fancy.

Also - feel free to PM me any questions or concerns you might have, I'd love to share more information or even ooh and aah at your creations if you wind up making something awesome!




I hope you guys have as much fun reading this as I did creating it. Happy posting

****
http://talk-to-stimey-please.1324083.n2.nabble.com/
beetlelisk
Profile Blog Joined July 2008
Poland2276 Posts
May 15 2012 02:09 GMT
#2
5/5 for effort
wwww
CyDe
Profile Blog Joined November 2011
United States1010 Posts
Last Edited: 2012-05-15 02:16:18
May 15 2012 02:13 GMT
#3
THANK YOU :D

You're so cool <3

EDIT: And a five outta five, of course
youtube.com/GamingCyDe-- My totally abandoned youtube channel that I might revisit at some point
Sc2Corpse
Profile Blog Joined December 2011
United States210 Posts
May 15 2012 02:48 GMT
#4
I just started getting involved in C++ because I may be going into computer science soon, but very nice! 5/5
The Zombie Protoss <3
og8456
Profile Joined May 2012
Korea (South)26 Posts
May 15 2012 13:09 GMT
#5
good! :D
my stream: http://ko.twitch.tv/prismccorby/
Skeggaba
Profile Blog Joined April 2009
Korea (South)1556 Posts
May 15 2012 13:20 GMT
#6
I missed an "m" and thought you were going to try to be a full time professional broodwar player, just like (Wiki)ruby ...
Bisu[about JD]=I was scared (laughs). The force emanating from his facial expression was so manly that I was even a little jealous.
icydergosu
Profile Blog Joined December 2009
528 Posts
May 15 2012 17:11 GMT
#7
If somebody wants to get a good Ruby introduction for beginners, i found Learn to program by Chris Pine very helpful.

http://pragprog.com/book/ltp2/learn-to-program
I am the Punishment of God. If you had not commited great sins, god would not have sent a punishment like me upon you.
GMarshal
Profile Blog Joined March 2010
United States22154 Posts
May 15 2012 17:14 GMT
#8
On May 15 2012 22:20 Skeggaba wrote:
I missed an "m" and thought you were going to try to be a full time professional broodwar player, just like (Wiki)ruby ...

I made the same mistake. :-P

Nice guide though 5/5 ^_^
Moderator
Anacletus
Profile Blog Joined April 2012
United States733 Posts
May 15 2012 20:11 GMT
#9
On May 16 2012 02:11 icydergosu wrote:
If somebody wants to get a good Ruby introduction for beginners, i found Learn to program by Chris Pine very helpful.

http://pragprog.com/book/ltp2/learn-to-program


Thanks for the additional sources to add - I've included it into the OP!


On May 16 2012 02:14 GMarshal wrote:
Show nested quote +
On May 15 2012 22:20 Skeggaba wrote:
I missed an "m" and thought you were going to try to be a full time professional broodwar player, just like (Wiki)ruby ...

I made the same mistake. :-P

Nice guide though 5/5 ^_^


Time to mark "Getting a 5/5 from a TL legend" off of my bucket list. Thanks :D!
http://talk-to-stimey-please.1324083.n2.nabble.com/
solidbebe
Profile Blog Joined November 2010
Netherlands4921 Posts
May 15 2012 20:22 GMT
#10
5/5 great guide!
That's the 2nd time in a week I've seen someone sig a quote from this GD and I have never witnessed a sig quote happen in my TL history ever before. -Najda
bre1010
Profile Blog Joined March 2009
71 Posts
May 15 2012 21:34 GMT
#11
I really like programming and I've been meaning to get into ruby for a while now. I appreciate this blog and keep making more!
JOJOsc2news
Profile Blog Joined March 2011
3000 Posts
Last Edited: 2012-05-17 01:15:12
May 17 2012 01:14 GMT
#12
Excellent blog post and great guide! Thank you!
5/5 and long live the #-beep- IRC Channel
✉ Tweets @sc2channel ⌦ Blog: http://www.teamliquid.net/blog/JOJO ⌫ "Arbiterssss... build more arbiterssss." Click 'Profile' for awesome shiro art!
Please log in or register to reply.
Live Events Refresh
Next event in 2h 54m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 454
StarCraft: Brood War
Britney 50597
Rain 5349
BeSt 1424
EffOrt 687
Larva 618
Light 404
Stork 384
Mini 377
firebathero 375
PianO 310
[ Show more ]
Rush 188
JulyZerg 153
Mind 133
Pusan 81
Aegong 72
sSak 58
Movie 46
sas.Sziky 37
scan(afreeca) 24
Shine 24
Shinee 23
Icarus 21
Noble 12
yabsab 10
SilentControl 7
ivOry 6
Bale 6
Terrorterran 2
Dota 2
qojqva3585
XcaliburYe294
canceldota84
League of Legends
Dendi1224
Counter-Strike
x6flipin661
sgares515
byalli393
Super Smash Bros
Mew2King110
amsayoshi29
Other Games
B2W.Neo2178
singsing2128
DeMusliM470
crisheroes419
XaKoH 286
Fuzer 250
Lowko206
markeloff68
ArmadaUGS43
Trikslyr35
QueenE6
Organizations
Other Games
gamesdonequick3836
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis1819
• Jankos1093
Upcoming Events
WardiTV European League
2h 54m
ShoWTimE vs sebesdes
Percival vs NightPhoenix
Shameless vs Nicoract
Krystianer vs Scarlett
ByuN vs uThermal
Harstem vs HeRoMaRinE
PiGosaur Monday
10h 54m
uThermal 2v2 Circuit
1d 2h
Replay Cast
1d 10h
The PondCast
1d 20h
WardiTV European League
2 days
Replay Cast
2 days
Epic.LAN
2 days
CranKy Ducklings
3 days
Epic.LAN
3 days
[ Show More ]
CSO Contender
4 days
BSL20 Non-Korean Champi…
4 days
Bonyth vs Sziky
Dewalt vs Hawk
Hawk vs QiaoGege
Sziky vs Dewalt
Mihu vs Bonyth
Zhanhun vs QiaoGege
QiaoGege vs Fengzi
Sparkling Tuna Cup
4 days
Online Event
5 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs Zhanhun
Dewalt vs Mihu
Hawk vs Sziky
Sziky vs QiaoGege
Mihu vs Hawk
Zhanhun vs Dewalt
Fengzi vs Bonyth
Esports World Cup
6 days
ByuN vs Astrea
Lambo vs HeRoMaRinE
Clem vs TBD
Solar vs Zoun
SHIN vs Reynor
Maru vs TriGGeR
herO vs Lancer
Cure vs ShoWTimE
Liquipedia Results

Completed

2025 ACS Season 2: Qualifier
RSL Revival: Season 1
Murky Cup #2

Ongoing

JPL Season 2
BSL 2v2 Season 3
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
BSL20 Non-Korean Championship
Championship of Russia 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters

Upcoming

CSL Xiamen Invitational
CSL Xiamen Invitational: ShowMatche
2025 ACS Season 2
CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
BSL Season 21
K-Championship
RSL Revival: Season 2
SEL Season 2 Championship
uThermal 2v2 Main Event
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.