background preloader

Ruby Tutorial with Code Samples

Ruby Tutorial with Code Samples

Hello Ruby on Rails world | mentalized There is a newer version of this article updated for Rails 3 To some people Rails have a fairly high learning curve. And certainly, it’s somewhat higher than, say, PHP. This is a step by step tutorial to getting over the first hurdle: Creating a “hello world” application in Ruby on Rails. It works in Rails 1.0 assuming you have ruby and rails already installed and working on your system: rails hello cd hello ruby script\generate controller hello Create a file called index.rhtml in app/views/hello, containing “Hello world”. ruby script\server Navigate to in your browser and be greeted with your friendly application: “Hello world” PS: is a lot prettier “Hello world”-ish page.

1.  Numbers Now that you've gotten everything setup , let's write a program! Open up your favorite text editor and type in the following: puts 1 + 2 Save your program (yes, that's a program!) Introduction to puts So what's going on in that program? puts 3 puts simply writes onto the screen whatever comes after it. Integer and Float In most programming languages (and Ruby is no exception) numbers without decimal points are called integers , and numbers with decimal points are usually called floating-point numbers , or more simply, floats Here are some integers: And here are some floats: In practice, most programs don't use floats; only integers. Simple Arithmetic So far, we've got all the makings of a simple calculator. puts 1.0 + 2.0 puts 2.0 * 3.0 puts 5.0 - 8.0 puts 9.0 / 2.0 This is what the program returns: (The spaces in the program are not important; they just make the code easier to read.) puts 1 + 2 puts 2 * 3 puts 5 - 8 puts 9 / 2 Mostly the same, right? Uh... except for that last one! A Few Things to Try

Where can i find the lyrics to the plaza sesamo theme song Your privacy is important to us Yahoo is part of the Yahoo family of brandsThe sites and apps that we own and operate, including Yahoo and Engadget, and our digital advertising service, Yahoo Advertising. Yahoo family of brands. When you use our sites and apps, we use CookiesCookies (including similar technologies such as web storage) allow the operators of websites and apps to store and read information from your device. Learn more in our cookie policy. cookies to: provide our sites and apps to you authenticate users, apply security measures, and prevent spam and abuse, and MeasurementWe count the number of visitors to our pages, the type of device they use (iOS or Android), the browser they use and the duration of their visit to our websites and apps. Your privacy choices technical identifiers and browsing and search data, for analytics, personalised advertising and content, advertising and content measurement, and audience research and services development.

What is a Turing machine? © Copyright B.J. Copeland, July 2000 Turing first described the Turing machine in an article published in 1936, 'On Computable Numbers, with an Application to the Entscheidungsproblem', which appeared in Proceedings of the London Mathematical Society (Series 2, volume 42 (1936-37), pp. 230-265). The head and the tape A Turing machine is an idealised computing device consisting of a read/write head (or 'scanner') with a paper tape passing through it. The tape is divided into squares, each square bearing a single symbol--'0' or '1', for example. The input that is inscribed on the tape before the computation starts must consist of a finite number of symbols. The read/write head is programmable. States The head contains a subdevice that I call the indicator. Atomic operations There are just six types of fundamental operation that a Turing machine performs in the course of a computation. These are called the primitive or atomic operations of the machine. The instruction table An example

Maze Generation: Growing Tree algorithm # An implementation of the "Growing Tree" algorithm. This one is # notable for it's ability to become nearly identical to Prim's # algorithm, or the Recursive Backtracking algorithm, depending on # how the cells are removed from the list that aggregates as the # algorithm runs. # This script allows you to play with those settings by specifying # the mode after the width and height parameters, as "random" (pull # the cell from list at random), "newest" (pull the newest cell), # "middle" (pull the cell from the middle of the list), "oldest" # (pull the oldest cell), or a combination of any of these, e.g # ruby growing-tree.rb 10 10 newest:50,random:50 # That would select the newest cell half of the time, and a random # cell the other half of the time. # commands as well, to be chosen in order, by separating them with # semicolons; each subcommand may then be a comma-delimited list of # options to select randomly: # ruby growing-tree.rb 10 10 "newest;newest;oldest,middle" # see what you get! # 1. # 2. end

Related: