際際滷

際際滷Share a Scribd company logo
Kookmin University
Graduate School of Busuness IT
e-Government System Development
 1蠍
What is the Ruby?
 meaning reading and writing Ruby is really easy
 it looks a lot like regular English!High-level
 meaning you don't need a compiler to write and run Ruby.InterpretedInterpreted
 everything in Ruby is an object.Object-oriented
 Marts design a language that emphasized human needs over tho
se of the computer, which is why Ruby is so easy to pick up.Easy to use
What is the Ruby?
Who made the Ruby?
 襷豸覈 ろ襦
 襦蠏碁襾
 襷豸覈 ろ襦  襭觜襯 螳覦 襦蠏碁襾語企.
朱蓋 れ豺 覿 . 螻燕蟲蟾讌 朱 襦蠏
覦 牛朱, 一覦 蟲 覲危覿襯 ,
 襷る  覦螻殊 豬. 2006
 , 襷  ろ 蟯  ろ語
 旧 郁規 豪 郁規朱 讌螻 
. 襷豸覈 蟆壱狩 4覈 企れ .
 豢: 1965 4 14 (49), 朱蓋 れ豺 覿 れ豺 
 : 一覦
Why made the Ruby?
 襷豸覈 ろ襦 : 襦蠏碁 讌 蟆
讀 蟆 訖襷 ,
 襦蠏碁襾瑚 讀蟇一讌襦 り給.
  襷 襦蠏碁覦 語企ゼ 讌襷, 蠏 企蟆 襷
譟燕  給. 螳 蠍磯 蟆 覲企 覲願鍵 蟇磯,
蟇一蟇磯, 覲旧″蟇磯, 覓 螳給.
 蠏碁 れる 襷譟誤襷 襷 語企ゼ 襷り 苦
.   語企殊 企螳 螳れ 螻褐語  螻
給. 蟾讌 蟆 伎語 豌 朱 襦
蠏碁襾瑚  襷る 蟆.
 襭觜襯 螳覦覃伎 襦蠏碁覦  觜襯願 所 
讌譴給.
codecademy
 http://www.codecademy.com/learn
Cloud 9 (Saas)
 https://c9.io
 Ubuntu + Rails + Ruby + IDE_Tool +(Git Hub)
Reference
: ろ襦襷豸覈
Rubyists bible
襷危碁豢豌: ろ襦襷豸覈 襷危碁豢豌
ろ襦豢豌
れ旧譯 觴♀鍵, 蠍謂.
Intro
Everything is object in Ruby
 ( 譯殊 #朱 螻 => 覈轟企ゼ ろ 覦 螳 .)
1.class #=>Fixnum
0.0.class #=>Float
True.class #=>TrueClass
False.class #=>FalseClass
Nil.class #=>NilClass
False.class #=>FalseClass
Nil.class #=>NilClass
1.class #=>Fixnum
Method (覃)
Method in Ruby
 Method form in ruby
def (parameter1, parameter2, parameter3)
Doing Something
end
 Parentheses are usually optional in Ruby.
 覲危 parameter 轟 襴伎   螳  牛.
end
Method in Ruby
 Implicit Return
 Parentheses are usually optional in Ruby.
 覲危 parameter 轟 襴伎   螳  牛.
Interpolation 覲願覯
Interpolation
 Interpolation
 Interpolation allows Ruby code to appear within a string. The result of evaluating t
hat code is inserted into the string:
 "1 + 2 = #{1 + 2}" #=> "1 + 2 = 3"
#{expression}
The end of the sentence
 Usually, Every sentence should be ended by semi-colon in Java or C
 But in Ruby, Dont care about it.
覿覓語(伎伎)
覓語(譬襭)覓語(譬襭)
覓語レ郁屋
Interpolation
 Interpolation
 Interpolation allows Ruby code to appear within a string. The result of evaluating t
hat code is inserted into the string:
 "1 + 2 = #{1 + 2}" #=> "1 + 2 = 3"
#{expression}
Dynamic Typing
 Ruby is dynamically typed: the type of a variable is generally not inferable until
runtime. So s=5 can follow s= foo in the same block of code.
 Because variables do not have types.
Dynamic Typing
 Ruby is dynamically typed: the type of a variable is generally not inferable until
runtime. So s=5 can follow s= foo in the same block of code.
 Because variables do not have types.
Dynamic Typing
 Ruby is dynamically typed: the type of a variable is generally not inferable until
runtime. So s=5 can follow s= foo in the same block of code.
 Because variables do not have types.
Every Operation is a Method Call
 every operation is a method call, note that even basic math operations
 such as +, *, = = (equality comparison) are syntactic sugar for method calls
Every Operation is a Method Call
 every operation is a method call, note that even basic math operations
 such as +, *, = = (equality comparison) are syntactic sugar for method calls
 syntactic sugar ( 危危螻 所 蠍 所 貉危 語企ゼ 誤  覓碁Д)
 (computing) Additions to a computer language that make code easier for humans
to read or write, but that do not change the functionality or expressiveness of the
language. -Wikipidea
Every Operation is a Method Call
 螳豌願 螳螻  蟆
 企  蟲譟
 螳豌伎 炎骸 覃
 覃  覲
襴 (Reflection)
襭觜 螳  語伎 襷 レ 譴  誤碁ろ(introspection) 螳ロる 企.
讀 襦蠏碁 れる 蠍一 蠍 覈 危エ 覲  る 覩.
Every Operation is a Method Call
  企れ 螳豌 
 (Fixnum,Symbol,true,nill 讀 螳 螳 螳豌企 覿螳)
 ObjectSpace.each_object(Some_class) {|x| p x}
襴 (Reflection)
Every Operation is a Method Call
 語ろ伎る伎 覃 
instance name.respond_to(method name)
襴 (Reflection)
Every Operation is a Method Call
 螳豌(語ろ伎) 伎 危エ覲企 蟆 襴  豸°  訖
 豌 蠏碁殊 至鍵 伎 企れ 伎  .
襴 (Reflection)
Every Operation is a Method Call
 螳豌(語ろ伎) 伎 危エ覲企 蟆 襴  豸°  訖
 豌 蠏碁殊 至鍵 伎 企れ 伎  .
襴 (Reflection)
Every Operation is a Method Call
 if something looks like a duck and quacks like a duck, it might as well be a duck.
 るΜ豌 覲伎願, るΜ豌 碁, 蠏瑚唄 るΜ 蟆企.
 螳豌伎  企れ 伎螳 , 覓伎   螳  蟆一 蟆企.
Duck Typing ; ( Viewpoint, philosophy )
EverythingEverything
is object
in Ruby.
Reflection.
Typing
Duck
Typing
Every Operation is a Method Call
 if something looks like a duck and quacks like a duck, it might as well be a duck.
 るΜ豌 覲伎願, るΜ豌 碁, 蠏瑚唄 るΜ 蟆企.
 螳豌伎  企れ 伎螳 , 覓伎   螳  蟆一 蟆企.
Duck Typing ; ( Viewpoint, philosophy )
豺
覦磯
蟆讌?
豺襷 覦朱 OK! 豺襷 螻螳 覦朱 OK!
Every Operation is a Method Call
 if something looks like a duck and quacks like a duck, it might as well be a duck.
 るΜ豌 覲伎願, るΜ豌 碁, 蠏瑚唄 るΜ 蟆企.
 螳豌伎  企れ 伎螳 , 覓伎   螳  蟆一 蟆企.
Duck Typing ; ( Viewpoint, philosophy )
Fileopen.class 殊願鍵class FileManagement{class FileManagement{
class FileManagement{
public void main(String Args[])
Fileopen.class
Modify.class
Save.class
殊願鍵
蠍
ロ蠍
class FileManagement{
public void main(String Args[])
if ( ! Fileopen  語ろ伎?){}
if ( ! Modify  語ろ伎?){}
if ( ! Save  語ろ伎?){}

}
class FileManagement{
public void main(String Args[])
if ( ! Fileopen  蠍磯レ 螳?){}
if ( ! Modify  蠍磯レ 螳?){}
if ( ! Save  蠍磯レ 螳?){}

}
if ( ! Fileopen  蠍磯レ 螳?){}
if ( ! Modify  蠍磯レ 螳?){}
if ( ! Save  蠍磯レ 螳?){}
襭觜 Dynamic typing朱 誤 覲
  螳覲企.
磯殊 螳 覦襯願,  襷豢
覃 .
 るΜ豌 覲伎願, るΜ豌 碁企
. 覦譯殊(laissez-faire)

}
Every Operation is a Method Call
Duck Typing ; ( Viewpoint, philosophy )
企  觜蟲 - JAVA, C#
Every Operation is a Method Call
Duck Typing ; ( Viewpoint, philosophy )
螳豌 覲伎 (覃) 蠍一 蟆
Every Operation is a Method Call
Duck Typing ; ( Viewpoint, philosophy )
覦譯殊ろ (laissez-faire)
Every Operation is a Method Call
 lets us define new code at runtime.
覃襦蠏碁覦(metaprogramming)
Every Operation is a Method Call
Iterator (Do-While)
Begin
#doing Something.
End while (true) #While not false or not nil.
Iterator (Do-While)
Begin
#doing Something.
End while (true) #While not false or not nil.
Iterator (While)
while (true) do #While not false or not nil
#doing Something.
End
Iterator (While)
while (true) do #While not false or not nil
#doing Something.
End
Iterator (For)
for var in collection
#doing Something.
End
Iterator (For)
for var in collection
#doing Something.
End
Iterator (Use the method)
Iterator (Each; Enumerable)
Collection.each do |var| doing something end
Collection.each { |var| doing something }
Hash, Array, Range  襷 企れ   each!
Blocks and Yield
Def call_back
puts Start of method
yield
yield
puts End of method
End
Result :
Start of method
In the block
In the block
End of method
Yield : 蟆譯朱, 
語ろ伎る.覃覈(argument) {|parameter| doing something.}
End
Call_block {puts In the block}
Def call_block
yield(hello, 99)
End
call_block {|str, num| } blockblock
Blocks and Yield
Blocks and Yield
Yield : 蟆譯朱, 
語ろ伎る.覃覈(argument) {|parameter| doing something.}
blockblock
Block 牛 inner function  inner method襯 蟲   .
Blocks and Yield
語ろ伎る.覃覈(argument) {|parameter| doing something.}
Blocks and Yield
Yield : 蟆譯朱, 
語ろ伎る.覃覈(argument) {|parameter| doing something.}
Blocks and Yield
Def each
for each element
yield(element)
end
end
詞豸
Each 覦覲旧 蟲煙 れ螻 螳 蟆企.
Proc & Lambda : Savable Blocks!
Proc & Lambda : Savable Blocks!
Proc Proc.new { puts "Hello!" }
Lambda lambda { puts "Hello!" }
Proc & Lambda : Savable Blocks!
Proc Lambda
Checking Arguments X O
if you pass it the wrong number of
arguments
Ignore
andassign nil
throw an error
control back to the calling method X O
讀譬襭 旧蟠覦
closure
closure : 企(closure) 企螳 碁 襷ル(context) 蠏狩   蟆 螳襯危.
企 碁 讌覲 蠏   ,
碁 ろ  碁螳 覃碁 危 企螳 碁 覲 蠏   .
企 覃貉る讀 企手 .
1
2
3
4
5
6
function factory_movie(title){
return {
get_title : function (){
return title;
ろ蟆郁骸
Ghost in the shell -> Matrix -> 螻糾蠍磯 -> Matrix
Javascript
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
return title;
},
set_title : function(_title){
title = _title
}
}
}
ghost = factory_movie('Ghost in the shell');
matrix = factory_movie('Matrix');
alert(ghost.get_title());
alert(matrix.get_title());
ghost.set_title('螻糾蠍磯');
alert(ghost.get_title());
alert(matrix.get_title());
closure
closure : 企(closure) 企螳 碁 襷ル(context) 蠏狩   蟆 螳襯危.
企 碁 讌覲 蠏   ,
碁 ろ  碁螳 覃碁 危 企螳 碁 覲 蠏   .
企 覃貉る讀 企手 .
(覃) A
int var1 1) Test =  A
2) Test ろ
return (覃) B
(覃) B
print var1
2) Test ろ
3) 蟆郁骸?
Var1 る螳 る螳?
Block
Proc
Lambda
closure
closure
def multiply(m) test = multiply(2) -> 碁 覲def multiply(m)
n = m
return lambda{|data|data.collect{|x| x*n}}
end
test = multiply(2)
puts test.call([1,2,3])
test = multiply(2) -> 碁 覲
def multiply(2)
n = 2
return lambda{|data|data.collect{|x| x*2}}
end
puts test.call([1,2,3]) ->
lambda{|[1,2,3]|[1,2,3].collect{|x| x*2}}
Lambda   覯 覦 螻, 覃 語 n
螳覩襦(Close Over) 企(Closure)手 .
closure
Lambda   覯 覦 螻, 覃 語 n
螳覩襦(Close Over) 企(Closure)手 .
Private 覲豌 伎 覈
- OOP  語ろ伎れ 蟆 覲伎碁.
closure
class
class
煙 (Constructor)
語ろ伎 覲(instance variable)
語ろ伎ろ (Instantiating)
Kinds of Variables
First letter Kinds Default value Example
Lowercase or _ Local variable
讌 覲
谿語^   local_var
@ Instance variable
語ろ伎 覲
Nil @instance_var
@@ Class variable 谿語^   @@class_var@@ Class variable
企 覲
谿語^   @@class_var
$ Grobal variable
 覲
Nil $global_var
Uppercase Constant

谿語^   CONSTANT_VAR
Inheritance
Methods visibility
Modules & Mix-in
蠍磯 (Method) :
覲 蠍磯
覲(Constant value) :
給 80% = 80




1936 覿螳  57SC

Alias = my car
Instance class
Instance
Modules & Mix-in
Modules & Mix-in
mix-in :
A mix-in is a set of related behaviors that can be added to any class.-
Fox, Armando; Patterson, David (2014-01-03). Engineering Software as a Service: An
Agile Approach Using Cloud Computing
NinJA
test
1
NinJA
NinJASon
test
1
test
2
 覈
讌 .
Modules & Mix-in
Modules & Mix-in
Thank you!

More Related Content

How to use the Ruby programing language

  • 1. Kookmin University Graduate School of Busuness IT e-Government System Development 1蠍
  • 2. What is the Ruby? meaning reading and writing Ruby is really easy it looks a lot like regular English!High-level meaning you don't need a compiler to write and run Ruby.InterpretedInterpreted everything in Ruby is an object.Object-oriented Marts design a language that emphasized human needs over tho se of the computer, which is why Ruby is so easy to pick up.Easy to use
  • 3. What is the Ruby?
  • 4. Who made the Ruby? 襷豸覈 ろ襦 襦蠏碁襾 襷豸覈 ろ襦 襭觜襯 螳覦 襦蠏碁襾語企. 朱蓋 れ豺 覿 . 螻燕蟲蟾讌 朱 襦蠏 覦 牛朱, 一覦 蟲 覲危覿襯 , 襷る 覦螻殊 豬. 2006 , 襷 ろ 蟯 ろ語 旧 郁規 豪 郁規朱 讌螻 . 襷豸覈 蟆壱狩 4覈 企れ . 豢: 1965 4 14 (49), 朱蓋 れ豺 覿 れ豺 : 一覦
  • 5. Why made the Ruby? 襷豸覈 ろ襦 : 襦蠏碁 讌 蟆 讀 蟆 訖襷 , 襦蠏碁襾瑚 讀蟇一讌襦 り給. 襷 襦蠏碁覦 語企ゼ 讌襷, 蠏 企蟆 襷 譟燕 給. 螳 蠍磯 蟆 覲企 覲願鍵 蟇磯, 蟇一蟇磯, 覲旧″蟇磯, 覓 螳給. 蠏碁 れる 襷譟誤襷 襷 語企ゼ 襷り 苦 . 語企殊 企螳 螳れ 螻褐語 螻 給. 蟾讌 蟆 伎語 豌 朱 襦 蠏碁襾瑚 襷る 蟆. 襭觜襯 螳覦覃伎 襦蠏碁覦 觜襯願 所 讌譴給.
  • 7. Cloud 9 (Saas) https://c9.io Ubuntu + Rails + Ruby + IDE_Tool +(Git Hub)
  • 8. Reference : ろ襦襷豸覈 Rubyists bible 襷危碁豢豌: ろ襦襷豸覈 襷危碁豢豌 ろ襦豢豌 れ旧譯 觴♀鍵, 蠍謂.
  • 10. Everything is object in Ruby ( 譯殊 #朱 螻 => 覈轟企ゼ ろ 覦 螳 .) 1.class #=>Fixnum 0.0.class #=>Float True.class #=>TrueClass False.class #=>FalseClass Nil.class #=>NilClass False.class #=>FalseClass Nil.class #=>NilClass 1.class #=>Fixnum Method (覃)
  • 11. Method in Ruby Method form in ruby def (parameter1, parameter2, parameter3) Doing Something end Parentheses are usually optional in Ruby. 覲危 parameter 轟 襴伎 螳 牛. end
  • 12. Method in Ruby Implicit Return Parentheses are usually optional in Ruby. 覲危 parameter 轟 襴伎 螳 牛. Interpolation 覲願覯
  • 13. Interpolation Interpolation Interpolation allows Ruby code to appear within a string. The result of evaluating t hat code is inserted into the string: "1 + 2 = #{1 + 2}" #=> "1 + 2 = 3" #{expression}
  • 14. The end of the sentence Usually, Every sentence should be ended by semi-colon in Java or C But in Ruby, Dont care about it. 覿覓語(伎伎) 覓語(譬襭)覓語(譬襭) 覓語レ郁屋
  • 15. Interpolation Interpolation Interpolation allows Ruby code to appear within a string. The result of evaluating t hat code is inserted into the string: "1 + 2 = #{1 + 2}" #=> "1 + 2 = 3" #{expression}
  • 16. Dynamic Typing Ruby is dynamically typed: the type of a variable is generally not inferable until runtime. So s=5 can follow s= foo in the same block of code. Because variables do not have types.
  • 17. Dynamic Typing Ruby is dynamically typed: the type of a variable is generally not inferable until runtime. So s=5 can follow s= foo in the same block of code. Because variables do not have types.
  • 18. Dynamic Typing Ruby is dynamically typed: the type of a variable is generally not inferable until runtime. So s=5 can follow s= foo in the same block of code. Because variables do not have types.
  • 19. Every Operation is a Method Call every operation is a method call, note that even basic math operations such as +, *, = = (equality comparison) are syntactic sugar for method calls
  • 20. Every Operation is a Method Call every operation is a method call, note that even basic math operations such as +, *, = = (equality comparison) are syntactic sugar for method calls syntactic sugar ( 危危螻 所 蠍 所 貉危 語企ゼ 誤 覓碁Д) (computing) Additions to a computer language that make code easier for humans to read or write, but that do not change the functionality or expressiveness of the language. -Wikipidea
  • 21. Every Operation is a Method Call 螳豌願 螳螻 蟆 企 蟲譟 螳豌伎 炎骸 覃 覃 覲 襴 (Reflection) 襭觜 螳 語伎 襷 レ 譴 誤碁ろ(introspection) 螳ロる 企. 讀 襦蠏碁 れる 蠍一 蠍 覈 危エ 覲 る 覩.
  • 22. Every Operation is a Method Call 企れ 螳豌 (Fixnum,Symbol,true,nill 讀 螳 螳 螳豌企 覿螳) ObjectSpace.each_object(Some_class) {|x| p x} 襴 (Reflection)
  • 23. Every Operation is a Method Call 語ろ伎る伎 覃 instance name.respond_to(method name) 襴 (Reflection)
  • 24. Every Operation is a Method Call 螳豌(語ろ伎) 伎 危エ覲企 蟆 襴 豸° 訖 豌 蠏碁殊 至鍵 伎 企れ 伎 . 襴 (Reflection)
  • 25. Every Operation is a Method Call 螳豌(語ろ伎) 伎 危エ覲企 蟆 襴 豸° 訖 豌 蠏碁殊 至鍵 伎 企れ 伎 . 襴 (Reflection)
  • 26. Every Operation is a Method Call if something looks like a duck and quacks like a duck, it might as well be a duck. るΜ豌 覲伎願, るΜ豌 碁, 蠏瑚唄 るΜ 蟆企. 螳豌伎 企れ 伎螳 , 覓伎 螳 蟆一 蟆企. Duck Typing ; ( Viewpoint, philosophy ) EverythingEverything is object in Ruby. Reflection. Typing Duck Typing
  • 27. Every Operation is a Method Call if something looks like a duck and quacks like a duck, it might as well be a duck. るΜ豌 覲伎願, るΜ豌 碁, 蠏瑚唄 るΜ 蟆企. 螳豌伎 企れ 伎螳 , 覓伎 螳 蟆一 蟆企. Duck Typing ; ( Viewpoint, philosophy ) 豺 覦磯 蟆讌? 豺襷 覦朱 OK! 豺襷 螻螳 覦朱 OK!
  • 28. Every Operation is a Method Call if something looks like a duck and quacks like a duck, it might as well be a duck. るΜ豌 覲伎願, るΜ豌 碁, 蠏瑚唄 るΜ 蟆企. 螳豌伎 企れ 伎螳 , 覓伎 螳 蟆一 蟆企. Duck Typing ; ( Viewpoint, philosophy ) Fileopen.class 殊願鍵class FileManagement{class FileManagement{ class FileManagement{ public void main(String Args[]) Fileopen.class Modify.class Save.class 殊願鍵 蠍 ロ蠍 class FileManagement{ public void main(String Args[]) if ( ! Fileopen 語ろ伎?){} if ( ! Modify 語ろ伎?){} if ( ! Save 語ろ伎?){} } class FileManagement{ public void main(String Args[]) if ( ! Fileopen 蠍磯レ 螳?){} if ( ! Modify 蠍磯レ 螳?){} if ( ! Save 蠍磯レ 螳?){} } if ( ! Fileopen 蠍磯レ 螳?){} if ( ! Modify 蠍磯レ 螳?){} if ( ! Save 蠍磯レ 螳?){} 襭觜 Dynamic typing朱 誤 覲 螳覲企. 磯殊 螳 覦襯願, 襷豢 覃 . るΜ豌 覲伎願, るΜ豌 碁企 . 覦譯殊(laissez-faire) }
  • 29. Every Operation is a Method Call Duck Typing ; ( Viewpoint, philosophy ) 企 觜蟲 - JAVA, C#
  • 30. Every Operation is a Method Call Duck Typing ; ( Viewpoint, philosophy ) 螳豌 覲伎 (覃) 蠍一 蟆
  • 31. Every Operation is a Method Call Duck Typing ; ( Viewpoint, philosophy ) 覦譯殊ろ (laissez-faire)
  • 32. Every Operation is a Method Call lets us define new code at runtime. 覃襦蠏碁覦(metaprogramming)
  • 33. Every Operation is a Method Call
  • 34. Iterator (Do-While) Begin #doing Something. End while (true) #While not false or not nil.
  • 35. Iterator (Do-While) Begin #doing Something. End while (true) #While not false or not nil.
  • 36. Iterator (While) while (true) do #While not false or not nil #doing Something. End
  • 37. Iterator (While) while (true) do #While not false or not nil #doing Something. End
  • 38. Iterator (For) for var in collection #doing Something. End
  • 39. Iterator (For) for var in collection #doing Something. End
  • 40. Iterator (Use the method)
  • 41. Iterator (Each; Enumerable) Collection.each do |var| doing something end Collection.each { |var| doing something } Hash, Array, Range 襷 企れ each!
  • 42. Blocks and Yield Def call_back puts Start of method yield yield puts End of method End Result : Start of method In the block In the block End of method Yield : 蟆譯朱, 語ろ伎る.覃覈(argument) {|parameter| doing something.} End Call_block {puts In the block} Def call_block yield(hello, 99) End call_block {|str, num| } blockblock
  • 44. Blocks and Yield Yield : 蟆譯朱, 語ろ伎る.覃覈(argument) {|parameter| doing something.} blockblock Block 牛 inner function inner method襯 蟲 .
  • 45. Blocks and Yield 語ろ伎る.覃覈(argument) {|parameter| doing something.}
  • 46. Blocks and Yield Yield : 蟆譯朱, 語ろ伎る.覃覈(argument) {|parameter| doing something.}
  • 47. Blocks and Yield Def each for each element yield(element) end end 詞豸 Each 覦覲旧 蟲煙 れ螻 螳 蟆企.
  • 48. Proc & Lambda : Savable Blocks!
  • 49. Proc & Lambda : Savable Blocks! Proc Proc.new { puts "Hello!" } Lambda lambda { puts "Hello!" }
  • 50. Proc & Lambda : Savable Blocks! Proc Lambda Checking Arguments X O if you pass it the wrong number of arguments Ignore andassign nil throw an error control back to the calling method X O 讀譬襭 旧蟠覦
  • 51. closure closure : 企(closure) 企螳 碁 襷ル(context) 蠏狩 蟆 螳襯危. 企 碁 讌覲 蠏 , 碁 ろ 碁螳 覃碁 危 企螳 碁 覲 蠏 . 企 覃貉る讀 企手 . 1 2 3 4 5 6 function factory_movie(title){ return { get_title : function (){ return title; ろ蟆郁骸 Ghost in the shell -> Matrix -> 螻糾蠍磯 -> Matrix Javascript 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 return title; }, set_title : function(_title){ title = _title } } } ghost = factory_movie('Ghost in the shell'); matrix = factory_movie('Matrix'); alert(ghost.get_title()); alert(matrix.get_title()); ghost.set_title('螻糾蠍磯'); alert(ghost.get_title()); alert(matrix.get_title());
  • 52. closure closure : 企(closure) 企螳 碁 襷ル(context) 蠏狩 蟆 螳襯危. 企 碁 讌覲 蠏 , 碁 ろ 碁螳 覃碁 危 企螳 碁 覲 蠏 . 企 覃貉る讀 企手 . (覃) A int var1 1) Test = A 2) Test ろ return (覃) B (覃) B print var1 2) Test ろ 3) 蟆郁骸? Var1 る螳 る螳? Block Proc Lambda
  • 54. closure def multiply(m) test = multiply(2) -> 碁 覲def multiply(m) n = m return lambda{|data|data.collect{|x| x*n}} end test = multiply(2) puts test.call([1,2,3]) test = multiply(2) -> 碁 覲 def multiply(2) n = 2 return lambda{|data|data.collect{|x| x*2}} end puts test.call([1,2,3]) -> lambda{|[1,2,3]|[1,2,3].collect{|x| x*2}} Lambda 覯 覦 螻, 覃 語 n 螳覩襦(Close Over) 企(Closure)手 .
  • 55. closure Lambda 覯 覦 螻, 覃 語 n 螳覩襦(Close Over) 企(Closure)手 . Private 覲豌 伎 覈 - OOP 語ろ伎れ 蟆 覲伎碁.
  • 57. class
  • 58. class 煙 (Constructor) 語ろ伎 覲(instance variable) 語ろ伎ろ (Instantiating)
  • 59. Kinds of Variables First letter Kinds Default value Example Lowercase or _ Local variable 讌 覲 谿語^ local_var @ Instance variable 語ろ伎 覲 Nil @instance_var @@ Class variable 谿語^ @@class_var@@ Class variable 企 覲 谿語^ @@class_var $ Grobal variable 覲 Nil $global_var Uppercase Constant 谿語^ CONSTANT_VAR
  • 62. Modules & Mix-in 蠍磯 (Method) : 覲 蠍磯 覲(Constant value) : 給 80% = 80 1936 覿螳 57SC Alias = my car Instance class Instance
  • 64. Modules & Mix-in mix-in : A mix-in is a set of related behaviors that can be added to any class.- Fox, Armando; Patterson, David (2014-01-03). Engineering Software as a Service: An Agile Approach Using Cloud Computing NinJA test 1 NinJA NinJASon test 1 test 2 覈 讌 .