-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta_ruby01.rb
71 lines (55 loc) · 1.23 KB
/
meta_ruby01.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#coding: utf-8
##メソッド調査
class Greeting
def initialize(text)
@text = text
end
def welcome
@text
end
end
my_object = Greeting.new("Hello")
p my_object.class
p my_object.class.instance_methods(false)
p my_object.instance_variables
##ボブのこころみ重複し過ぎ
#テーブルにtitleが含まれる、Movieクラスにも@titleが含まれる
class Entity
def initialize(table,ident)
@table = table
@ident = ident
#Database.sql "INSERT INTO #{@table} (id) VALUES (#{@ident})"
end
def set(col, val)
#Database.sql "UPDATE #{@talbe} SET #{col}='val' WHERE id=#{@ident}"
end
def get(col)
#Database.sql("SELECT #{col} FROM #{@table} WHERE id=#{}")[0][0]
end
end
class Movie < Entity
def initialize(ident)
super("movies", ident)
end
def title
get("title")
end
def title=(value)
set("title", value)
end
def director
get("director")
end
def director=(value)
set("director", value)
end
end
movie = Movie.new(1)
movie.title = "博士の以上な愛情"
movie.director = "スタンリー・キューブリック"
require 'rubygems'
require 'active_record'
class Movie < ActiveRecord::Base
end
movie = Movie.create
movie.title = "博士の異常な愛情"