-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta_ruby2_3_1.rb
53 lines (46 loc) · 1.17 KB
/
meta_ruby2_3_1.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#coding: utf-8
require 'ruport'
table = Ruport::Data::Table.new :column_names => ["country", "wine"],
:data => [["France", "Bordeaux"],
["Italy", "Chianti"],
["France", "Chablis"]]
puts table.to_text
#動的表現で気にする事は下記のcountryである。
#作者は私がcountryという文言を使う事を想定していたのであろうか??
found = table.rows_with_country("France")
found.each do |row|
puts row.to_csv
end
class MyOpenStruct
def initialize
@attributes = {}
end
def method_missing(name, *args)
#nameには”flavor=”が入る
attribute = name.to_s
if attribute =~ /=$/
@attributes[attribute.chop] = args[0]
else
@attribute[attribute]
end
end
end
o = MyOpenStruct.new
o.flavor = "バニラ"
#複数引数の確認
#def test_args(*args)
# args.each do |val|
# p val
# end
#end
#test_args("aa", "bb")
#正規表現確認
#行末マッチ
#p "test=" =~ /=$/
#chop確認
#最終文字をなくす
#p "aaabb".chop
#ハッシュ確認
# hash = {}
# hash["flavor"] = "hashtest"
# p hash[:flavor]