Skip to content

Commit

Permalink
struct thing added
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthikeyan A K committed May 6, 2013
1 parent 46cc76d commit 6cb83b0
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 0 deletions.
9 changes: 9 additions & 0 deletions open_struct.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# open_struct.rb

require 'ostruct'

p = OpenStruct.new
p.name = "Karthik"
p.age = 30
puts "Hello, I am #{p.name}, age #{p.age}"

10 changes: 10 additions & 0 deletions struct_about_me.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# struct_about_me.rb

person = Struct.new :name, :age do
def about_me
"Hello, I am #{self.name}, age #{self.age}"
end
end
p = person.new "Karthik", 30
puts p.about_me

8 changes: 8 additions & 0 deletions struct_about_me_1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
person = Struct.new :name, :age do
def about_me
"Hello, I am #{@name}, age #{@age}"
end
end
p = person.new "Karthik", 30
puts p.about_me

8 changes: 8 additions & 0 deletions struct_about_me_2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
person = Struct.new :name, :age do
def about_me
"Hello, I am #{person.name}, age #{person.age}"
end
end
p = person.new "Karthik", 30
puts p.about_me

9 changes: 9 additions & 0 deletions struct_constant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# struct_constant.rb

Person = Struct.new :name, :age
p = Person.new
p.name = "Karthik"
p.age = 30

puts "Hello, I am #{p.name}, age #{p.age}"

7 changes: 7 additions & 0 deletions struct_one_line.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# struct_one_line.rb

person = Struct.new :name, :age
p = person.new "Karthik", 30

puts "Hello, I am #{p.name}, age #{p.age}"

9 changes: 9 additions & 0 deletions struct_start.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# struc_start.rb

person = Struct.new :name, :age
p = person.new
p.name = "Karthik"
p.age = 30

puts "Hello, I am #{p.name}, age #{p.age}"

10 changes: 10 additions & 0 deletions struct_wrong.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# struct_wrong.rb

person = Struct.new :name, :age
p = person.new
p.name = "Karthik"
p.age = 30
p.profession = "Engineer"

puts "Hello, I am #{p.name}, age #{p.age}, and I am on a #{p.profession}"

0 comments on commit 6cb83b0

Please sign in to comment.