Ruby rails Notes [Rails for Dot NET developers excerpt]

Source: Internet
Author: User
Tags dot net redmine
In Ruby's object-oriented world, we work with objects and Methods . Unlike VB. net, where some subroutines return a value (functions) and others do not (subs), all Ruby methods must return a value. when an explicit return statement is not used, the last-evaluated expression automatically becomes the return value.

Variables are not declared prior to their use. Ruby automatically allocates memory for variables upon extends rst use, and it also assigns their type based on inference. Like. Net, a garbage collector will reclaim memory automatically.

• There is no distinction made between methods, properties, and stored ELDS (or "member variables") like there is in. net.Ruby has only the concept of methods. However, Ruby classes do sport a convenient syntax for De marshning "Attribute methods," which are equivalent to De marshning. net properties. attr_reader and attr_accessor automatically de fi ne methods that provide property-like access to instance variables.

Comments start with the hash character (#), Unless the hash occurs inside a double-quoted string. Everything after the hash is ignored. There is no multiline comment character in ruby.

• Ruby classes may de javasne instance methods and class methods. Class methods are called static methods in. net.

Methods can be declared public, protected, or private, and these visibility scopes have the same meaning as they do in. net. There is no ruby equivalent for "internal" or "Assembly-level" visibility.

• Instance variable names must start with an AT (@) Sign and are always private. Class variables, or what we might call static variables in. net, start with two at signs. the rules for memory allocation and object assignment for class variables can get pretty strange in ruby, so we tend to avoid using them, especially since rails provides an alternative syntax for using class variables in Rails Applications.

• Ruby classes can be derived from only one base class but can"Mix in" any number of modules.A module in ruby is simply a set of related methods packaged together using the module key-word instead of class.

• There is no separate compilation step in ruby. If we execute this ruby code:

Name = 'job'

Len = Name. Length

Puts name + "has" + Len. to_s + "letters in his name ."

Puts "\ t #{5*10 }"

Puts "Hello, # {name}. You have # {name. Length} letters in your name"

# Searching and replacing

WORD = "restaurant"

Puts word. Index ('A') # prints 4

Puts word. Index ("ant") # prints 7

Puts word. Index (/st. + NT $/) # prints 2

Puts word. Index (/ant $/I) # prints 7

Puts word. Index ('buffet ') # prints "nil"

Flight = "United Airlines, Flight #312, ord to LAX, am to am"

Puts flight. sub ('united', 'American ')

Puts flight. sub (/(\ W +) to/, 'pdx ')

Puts flight. gsub ('am', 'pm ')

# Trimming whitespace

Flight = "United Airlines, Flight #312, am to am"

Flight = flight. gsub (/^ \ s +/, '') # Remove leading whitespace

Flight = flight. gsub (/\ s + $/, '') # Remove trailing whitespace

Flight = flight. Strip # removes leading and trailing whitespace

 

Development Environment

You can use the command line to complete development.CodeNavigation, function definition list, refactoring and other higher efficiency, using IDE is a better choice

Ruby in Steel

Commercial Software [60-day free trial]

Vs-based plug-ins

Aptana radrails

Open source software

Eclipse-based

API and interface references, books

Rdoc

Command Line input: Gem Server

You can view the installed rdoc file at http: // localhost: 8808.

Rails Manual

Www.railsbrain.com can be downloaded or viewed online.

Searching is more convenient than rdoc [use Firefox when ie cannot view]

Books

Chinese version of programming Ruby

Agile web development with rails 3rd edition

Rails for Dot NET developers

Open-source project reference

Redmine: http://www.redmine.org

Install

Follow the installation instructions on the site to run the [rack version must be consistent]

Analysis

Use radrails "import"-> "existing folder as new project" to view and analyze

Entry:

Config/routes. RB defines the ing between controllers, as shown in figure

Map. Home '',: controller => 'Welcome'

Contents of the welcome_controller.rb welcome directory under the controllers views directory in the consumer app

This project involves a lot of concepts and related processing, and initially understands that this estimation can basically be applied.

 

For more details, refer to books.

Rails for. NET developers Http://www.amazon.com/Rails-NET-Developers-Facets-Ruby/dp/1934356204/ref=la_B0034OUD06_1_1? Ie = utf8 & qid = 1343220323 & sr = 1-1

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.