Class: User

Inherits:
Object
  • Object
show all
Defined in:
lib/common/data_model.rb

Overview

User 表示一个用户目前的实现只是一个普通的数据模型,没有行为

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, password = ConfigHelper::CONF['default_password'], url = name, portrait = nil, sex = 1) ⇒ User

创建User

  • name 用户名,必填项

  • password 密码,选填项,默认值 passme123

  • url url前缀名,选填项,默认与name相同

  • portrait 头像加密串,选填项,默认为nil

  • sex 性别,1男,2女,默认值1

Example #1:

user_A = User.new “ruguo” user_B = User.new “ruguo2”,“1234” user_C = User.new “ruguo4”,“1234”,“ruguo”,“fl3k2jr23jr5o2u5o214”



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/common/data_model.rb', line 34

def initialize(name, password=ConfigHelper::CONF['default_password'], url=name, portrait=nil, sex=1)
	# 用户名
	@name = name
	# 用户密码
	@password = password
	# 空间url
	@url = url
	# 头像加密串 uid+uname
	@portrait = portrait
	# 性别
	@sex = sex
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



20
21
22
# File 'lib/common/data_model.rb', line 20

def name
  @name
end

#passwordObject

Returns the value of attribute password.



20
21
22
# File 'lib/common/data_model.rb', line 20

def password
  @password
end

#portraitObject

Returns the value of attribute portrait.



20
21
22
# File 'lib/common/data_model.rb', line 20

def portrait
  @portrait
end

#sexObject

Returns the value of attribute sex.



20
21
22
# File 'lib/common/data_model.rb', line 20

def sex
  @sex
end

#urlObject

Returns the value of attribute url.



20
21
22
# File 'lib/common/data_model.rb', line 20

def url
  @url
end

Instance Method Details

#==(obj) ⇒ Object

重载==,方便User对象之间的比较

Example #1:

a = User.new “ruguo”,“pass”,“ruguo” b = User.new “ruguo”,“pass33”,“ruguo33” c = User.new “ruguo11”,“pass33”,“ruguo33” d = Object.new

puts a == b #=> true puts a == c #=> false puts a == d #=> false



70
71
72
# File 'lib/common/data_model.rb', line 70

def ==(obj)
	obj.kind_of?(User) and obj.name == @name 
end

#to_sObject

重载之,方便日志打印

Example #1:

user = User.new “ruguo”,“pass”,“ruguo” puts user # => #<User:0x00000000b19220 @name=“ruguo”, @password=“pass”, @space_url=“ruguo”, @portrait=nil>



54
55
56
# File 'lib/common/data_model.rb', line 54

def to_s
	inspect
end