my-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/account_service/account.rb +16 -0
- data/lib/account_service/account_collection.rb +19 -0
- data/lib/admin.rb +24 -0
- data/lib/hello_world.rb +2 -0
- data/lib/radio.rb +53 -0
- data/lib/service/user_service.rb +9 -0
- data/lib/user.rb +45 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 392dc7083526fe6e0b977f4176acb4436a7fbf3a53e95d69269bf13d2ecd2c12
|
4
|
+
data.tar.gz: 799c5a2dd326c774848dcdaa44e22e830f9cb3d5f81f604ae95ba78bddcb7eba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6900fb2e4f558e57d3a583a34efa06da2fea25887900aca4fb114bd67e6392dadcd81fef56bcd522bcdcf684283f922cc0574a88260c183f0db74c9bd32d4fcb
|
7
|
+
data.tar.gz: 4c0e590807faea2cc55ee3407935794de20863779fee1b607aaf2cb29dbe0764fc3f5b9b05736fcb67443bef342b97ed8c64fe8fa69bb07785c8f12044c14d40
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Account
|
2
|
+
include Comparable
|
3
|
+
|
4
|
+
attr_accessor :name, :id
|
5
|
+
attr_accessor :balance
|
6
|
+
|
7
|
+
def initialize(name, balance = 0)
|
8
|
+
@name = name
|
9
|
+
@balance = balance
|
10
|
+
@id = rand(10)
|
11
|
+
end
|
12
|
+
|
13
|
+
def <=>(other)
|
14
|
+
@balance <=> other.balance
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'account'
|
2
|
+
|
3
|
+
class AccountCollection
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@accounts = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(account)
|
11
|
+
@accounts << account
|
12
|
+
end
|
13
|
+
|
14
|
+
def each
|
15
|
+
@accounts.each do |account|
|
16
|
+
yield account
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/admin.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# require './user'
|
2
|
+
require_relative 'user'
|
3
|
+
# require './service/user_service'
|
4
|
+
require_relative 'service/user_service'
|
5
|
+
|
6
|
+
class Admin < User
|
7
|
+
|
8
|
+
attr_accessor :admin_type
|
9
|
+
|
10
|
+
def initialize(name)
|
11
|
+
super(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def manage_user(user)
|
15
|
+
puts "manage user #{user.name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def who
|
19
|
+
Service::UserService.new.to_string
|
20
|
+
super
|
21
|
+
puts 'i am an admin'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/hello_world.rb
ADDED
data/lib/radio.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
class Radio
|
2
|
+
|
3
|
+
@@brand = 'SONY_DALIAN'
|
4
|
+
|
5
|
+
MAX_VOLUME = 100
|
6
|
+
MIN_VOLUME = 0
|
7
|
+
|
8
|
+
attr_reader :volume
|
9
|
+
# attr_writer :volume
|
10
|
+
# attr_accessor :volume
|
11
|
+
|
12
|
+
def initialize(volume = 3)
|
13
|
+
@volume = volume
|
14
|
+
end
|
15
|
+
|
16
|
+
# def volume
|
17
|
+
# @volume
|
18
|
+
# end
|
19
|
+
|
20
|
+
def volume=(volume)
|
21
|
+
@volume = volume if check_volume volume
|
22
|
+
end
|
23
|
+
|
24
|
+
def volume_to_1000
|
25
|
+
self.volume = 1000 #调用的是volumn= 方法, 不是直接给@volume赋值
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.brand
|
29
|
+
@@brand
|
30
|
+
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
|
34
|
+
def wave_band
|
35
|
+
'100.8'
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def check_volume(volume)
|
41
|
+
MAX_VOLUME > volume && volume > MIN_VOLUME
|
42
|
+
end
|
43
|
+
|
44
|
+
private :check_volume
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
class << Radio
|
49
|
+
def hack
|
50
|
+
puts 'I hacked in the radio'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
data/lib/user.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
class User
|
2
|
+
|
3
|
+
attr_accessor :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
@login_status = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def login
|
11
|
+
puts "user #{name} logged in"
|
12
|
+
self.login_status = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def logout
|
16
|
+
puts "user #{name} logged out"
|
17
|
+
self.login_status = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def login?
|
21
|
+
self.login_status
|
22
|
+
end
|
23
|
+
|
24
|
+
def loginx?
|
25
|
+
self.check_login_status
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_who
|
29
|
+
who
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def check_login_status
|
35
|
+
login_status
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_accessor :login_status
|
41
|
+
|
42
|
+
def who
|
43
|
+
puts "this is #{name}"
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: my-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sgao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is my first gem!
|
14
|
+
email: sgao@beckman.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/account_service/account.rb
|
20
|
+
- lib/account_service/account_collection.rb
|
21
|
+
- lib/admin.rb
|
22
|
+
- lib/hello_world.rb
|
23
|
+
- lib/radio.rb
|
24
|
+
- lib/service/user_service.rb
|
25
|
+
- lib/user.rb
|
26
|
+
homepage: https://github.com/sgao-becls/ruby-demo
|
27
|
+
licenses: []
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubygems_version: 3.1.4
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: A ruby demo
|
48
|
+
test_files: []
|