This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc = Proc.new { |x| x + 1 } | |
puts proc.call(2) | |
result = lambda { |x| x + 1 } | |
puts result.call(2) | |
proc = Proc.new { |x| x + 1 } | |
puts proc.call(2,3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc = Proc.new { |x| x + 1 } | |
puts proc.call(2) | |
result = lambda { |x| x + 1 } | |
puts result.call(2) | |
proc = Proc.new { |x| x + 1 } | |
puts proc.call(2,3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kata | |
A = 5 | |
module Dojo | |
B = 9 | |
A = 7 | |
class ScopeIn | |
def push | |
A | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent | |
private | |
def name | |
'Testing' | |
end | |
end | |
p = Parent.new | |
error: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# class Parent | |
# def knox | |
# puts 'parent' | |
# end | |
# end | |
# class Child < Parent | |
# def knox | |
# puts 'child' | |
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rescue la noi de xu ly ngoai le. | |
# raise is phuong thuc giup chung ta dua ra ngoai le. Dua ra ngoai le hien tai. Neu ko co thi bi loi RuntimeError | |
# retry: lap lai code o begin. | |
# ensure tuong tu finally | |
# throw/catch : sau catch la 1 block. tiep tuc xu li khi gap throw thi vang ra ngoai tuong tu nhu break | |
begin | |
file = open("file_name.txt") | |
if file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [ "a", "b", "c", "d" ] | |
p a.map{|x| x + "!" } | |
p a | |
a = [ "a", "b", "c", "d" ] | |
p a.map!{|x| x + "!" } | |
p a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails cung câp 2 khai báo mối quan hệ nhiều nhiều | |
1. has_and_belongs_to_many | |
2. has_many :through | |
Ví dụ: | |
Student và Course |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Quan hệ đa hình trong rails | |
Giả sử có có 2 model Course and Lab. Tiết học và Lab đều cần trợ giảng. | |
Vì vậy nếu sử dụng has_many/belongs_to ở đây. sẽ phải cần | |
2 model tương tự nhau giữa TA of course và TA of Lab. Thay vì có | |
2 model khác nhau.bạn có thể chỉ cần có 1. Bạn có thể liên kết model | |
này với mỗi bên bằng cách sữ dụng quan hệ đa hình. | |
rails g model TeachingAssistant name:string ta_duty_id:integer ta_duty_type:string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Sign up</h2> | |
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> | |
<%= devise_error_messages! %> | |
<%= fields_for @user_detail do |u| %> | |
<div class="field"> | |
<%= u.label :name %><br /> | |
<%= u.text_field :name %> | |
</div> |
OlderNewer