Skip to content

Commit 73e2ede

Browse files
committed
Add classes chapter
1 parent f995573 commit 73e2ede

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Programmer
2+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'rspec'
2+
3+
[['solution::code']]
4+
5+
describe 'Your code' do
6+
it "defines a class Programmer" do
7+
expect(Object.const_defined?('Programmer')).to be true
8+
end
9+
10+
if Object.const_defined?('Programmer')
11+
describe Programmer do
12+
it "allows instantiating a new Programmer" do
13+
expect { Programmer.new }.not_to raise_error
14+
end
15+
16+
it "defines a Programmer class without any methods" do
17+
expect(Programmer.public_instance_methods(false)).to be_empty
18+
expect(Programmer.singleton_methods(false)).to be_empty
19+
expect(subject.protected_methods(false)).to be_empty
20+
expect(subject.private_methods(false)).to be_empty
21+
end
22+
end
23+
24+
end
25+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Your first class
2+
3+
You can define a class with the *class* keyword followed by the
4+
camelcased name of the class.
5+
Keep in mind to close the class definition with the *end* keyword, e.g.:
6+
7+
`class ClassName`
8+
`end`
9+
10+
Camelcasing the class name is not necessary, but is a naming convention in Ruby.
11+
12+
---
13+
14+
Define a class *Programmer* similar to the example above!
15+
16+
---

0 commit comments

Comments
 (0)