ruby on rails – 1. ruby

Download Ruby on Rails – 1. Ruby

Post on 02-Jan-2016

86 views

Category:

Documents

11 download

Embed Size (px)

DESCRIPTION

Ruby on Rails 1. Ruby. Aon 1 . Ruby ?. ( ) Perl + Smalltalk + Ada + Eiffel + Lisp => Ruby Imperative, Functional, following OOP. Yukihiro Matsumoto. Ruby ?. - PowerPoint PPT Presentation

TRANSCRIPT

PowerPoint

Ruby on Rails 1. RubyAon 1Ruby ? ( )

Perl + Smalltalk + Ada + Eiffel + Lisp => Ruby

Imperative, Functional, following OOP

Yukihiro MatsumotoRuby ?Ruby = an interpreted scripting language for quick and easy object-oriented programming!Ruby ?Ruby = an interpreted scripting language for quick and easy object-oriented programming!

- OS call - - Ruby ?Ruby = an interpreted scripting language for quick and easy object-oriented programming!

- - -

Ruby ?Ruby = an interpreted scripting language for quick and easy object-oriented programming!

- (class, method, inheritance)- module - singleton method

Ruby ?Ruby = an interpreted scripting language for quick and easy object-oriented programming!

- - - !(40! ?)-

!Ruby interpreter shell irb .(irb = interactive ruby)

Ruby .rb .

$ ruby .rb .

#! /usr/bin/env ruby ./.rb .( chmod +x .rb ? )Ruby

Ruby

!! puts java println print java print # Ruby

Ruby Integer : Fixnum Integer : Bignum

1234 => Fixnum123412341234123412341234123412341234 => Bignum23.5432 => Float12_23 => Fixnum ( underscore )Ruby Math module method- cos(x), sin(x) : - log(x), exp(x) : , - sqrt(x) : - abs Ruby String

=> Escape + * !Ruby ASCII Ruby String

Substring [, ], .. : , : String equality) #{} String .123#{2+2} => 123418Ruby StringString method- to_c, to_i, to_f, to_r : string , , , => string.to_c - length : string - split(pattern) : parameter string - strip : whitespace - reverse : string - replace : - method http://ruby-doc.org/core-2.0/String.html

Array, Hash

Control Structure- if

if bool_expression1 #your code hereelsif bool_expression2 or your code if bool_expression #your code hereelse #your code hereendControl Structure- case

case xwhen case1 #your code herewhen case2 #your code hereendControl Structure- while

while bool_expression expressionend

your code while bool_expression

Control Structure- for

for element in collection #your code hereendIterationstring iterator=> each_byte : string iterator=> each_line : strin iterator

Array, Hash each, each_key, each_value

yield retry code ."abc".each_byte{|c| printf "", c}; print "\n"a\nb\nc\n".each_line{|l| print l}

ruby>def repeat(num) | while num > 0 | yield | num -= 1 | end |end nilruby>repeat(3) { puts "foo" }foofoofoo nil

ruby>def WHILE(cond) | return if not cond | yield | retry |end nilruby>i=0; WHILE(i global variable class Reader and writerclass person def initialize(name) @name = name end def read_name @name end def write_name(name) @name = name endendReader and writerclass person def initialize(name) @name = name end attr_reader :name attr_writer :nameendpublic private protected classMyClass defmethod1#defaultis'public' #... end protected#subsequentmethodswillbe'protected' defmethod2#willbe'protected' #... end private#subsequentmethodswillbe'private' defmethod3#willbe'private' #... end public#subsequentmethodswillbe'public' defmethod4#andthiswillbe'public' #... end end Alternatively, you can set access levels of named methods by listing them as arguments to the access control functions.classMyClass defmethod1 end #...andsoon public:method1,:method4 protected:method2 private:method3 end35Inheritanceclass subclass_name < class_name function1 function2 function3end

classKaraokeSong