Skip to content

Instantly share code, notes, and snippets.

@piyush8
Created March 25, 2016 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piyush8/0b8577f1d512815e9be7 to your computer and use it in GitHub Desktop.
Save piyush8/0b8577f1d512815e9be7 to your computer and use it in GitHub Desktop.
class Student
def initialize(name,roll_no,age,address,subject1,subject2,subject3,subject4,subject5,subject6)
@name = name
@roll_no = roll_no
@age = age
@address = address
@subject1 = subject1
@subject2 = subject2
@subject3 = subject3
@subject4 = subject4
@subject5 = subject5
@subject6 = subject6
end
#def to_s
# "Student: #@name,#@roll_no,#@age,#@address,#@subject1,#@subject2,#@subject3,#@subject4,#@subject5,#@subject6"
#end
attr_accessor :name,:roll_no, :age,:address, :subject1, :subject2, :subject3,:subject4, :subject5, :subject6
def sum
return @subject1+@subject2+@subject3+@subject4+@subject5+@subject6
end
end
student1 = Student.new("Rakesh",111,12,"hyd",70,62,74,83,65,81)
student2 = Student.new("Raju",112,13,"vjd",61,55,66,82,79,66)
student3 = Student.new("Balu",113,15,"bngl",61,90,60,71,63,90)
student4 = Student.new("Kiran",114,14,"mncl",74,81,78,74,56,54)
student5 = Student.new("Rajesh",115,11,"adb",51,55,68,94,76,67)
student6 = Student.new("Prakash",116,12,"kmng",71,68,63,74,81,80)
student7 = Student.new("Prashant",117,13,"jgt",73,58,92,81,76,69)
student8 = Student.new("Ramesh",118,11,"nzb",72,69,77,80,45,68)
student9 = Student.new("Mahesh",119,15,"rcr",78,85,55,64,71,88)
student10 = Student.new("Aditya",120,12,"ktp",67,59,62,77,74,98)
ObjectSpace.each_object (Student) {|i| puts i.name}
#puts student1.each_with_index { |a,i | a.name }
#ObjectSpace.each_object(Student) {|j| puts j.roll_no }
#p Student.instance_methods
#p student1[attr_name]
p student9.instance_variable_get(:@roll_no)
print "#{student1.subject1},#{student1.subject2},#{student1.subject3},#{student1.subject4},#{student1.subject5},#{student1.subject6}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment