This file contains hidden or 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
function Company(name, addr) { // Entityクラス | |
this.name = name; | |
this.addr = addr; | |
// | |
this._entity = this; // 姑息な方法 | |
} | |
function Supplier(company) { // Roleクラス | |
this.__proto__ = company; | |
this.products = []; // 商品一覧 (Role固有のデータ) |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
## | |
## 問題5:入れ子になっているリストを、インデント幅2の文字列に変換する関数 indented(arr, width=2) を定義してください。 | |
## 例: | |
## nested = [1, [2, [3, 4], 5, [6]]] | |
## string = indented(nested) | |
## print(string) | |
## #=> 1 | |
## # 2 |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
## | |
## 問題4:入れ子になっているリストを、入れ子を外すような関数 flatten(arr) を定義してください。 | |
## 例: | |
## nested = [1, [2, [3, 4], 5, [6]]] | |
## arr = flatten(nested) | |
## print(arr) | |
## #=> [1, 2, 3, 4, 5, 6] | |
## |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
## | |
## 問題3: シーケンスseqと関数keyを受け取り、要素のリストを値とするような辞書を返すような関数 group_by(seq, key) を定義してください。 | |
## 例: | |
## seq = [ {'id': 1, 'name': "Haruhi", 'gender': "F"}, | |
## {'id': 2, 'name': "Mikuru", 'gender': "F"}, | |
## {'id': 3, 'name': "Yuki", 'gender': "F"}, | |
## {'id': 4, 'name': "Ituki", 'gender': "M"}, | |
## {'id': 5, 'name': "Kyon", 'gender': "M"}, |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
## | |
## 問題2: シーケンスseqと関数keyを受け取り、要素を値とする辞書を返すような関数 index_by(seq, key) を定義してください。 | |
## 例: | |
## seq = [ {'id': 1, 'name': "Haruhi", 'gender': "F"}, | |
## {'id': 2, 'name': "Mikuru", 'gender': "F"}, | |
## {'id': 3, 'name': "Yuki", 'gender': "F"}, | |
## {'id': 4, 'name': "Ituki", 'gender': "M"}, | |
## {'id': 5, 'name': "Kyon", 'gender': "M"}, |
This file contains hidden or 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
""" | |
問題1: シーケンスを受け取り、N個ずつの配列にして返すような関数 each_slice(seq, n, default=None) を定義してください。 | |
例: | |
seq = [10, 20, 30, 40, 50, 60, 70] | |
for item in each_slice(seq, 3): | |
print(item) | |
## 結果: | |
[10, 20, 30] | |
[40, 50, 60] |
This file contains hidden or 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
~$ telnet cache.ruby-lang.org 80 | |
Trying 103.245.222.184... | |
Connected to fallback.global-ssl.fastly.net. | |
Escape character is '^]'. | |
GET /pub/ruby/ HTTP/1.0 | |
Host: cache.ruby-lang.org | |
HTTP/1.1 200 OK | |
Server: nginx/1.2.1 | |
Content-Type: text/html |
This file contains hidden or 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
-- | |
-- data | |
-- | |
psql=> select * from users; | |
id | name | |
----+------- | |
1 | Bob | |
2 | Alice | |
3 | John | |
(3 rows) |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
require 'baby_erubis' | |
erb = BabyErubis::Html.new.from_str <<'END', __FILE__, __LINE__+1 | |
<html> | |
<body> | |
<ul> | |
<% (1..3).each do %> | |
<li><%= x %></li> |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
require 'erb' | |
erb = ERB.new <<'END' | |
<html> | |
<body> | |
<ul> | |
<% (1..3).each do %> | |
<li><%= x %></li> |