Skip to content

Instantly share code, notes, and snippets.

@psylone
Created June 20, 2014 10:12
Show Gist options
  • Save psylone/eb4bc2252008eceb40d7 to your computer and use it in GitHub Desktop.
Save psylone/eb4bc2252008eceb40d7 to your computer and use it in GitHub Desktop.
# code_1
class Point
end
# puts Point.new
# code_1.1
# class Point
# def initialize
# p "I am a Point!"
# end
# end
# p Fixnum.superclass.superclass.superclass.superclass
# p Point.superclass.superclass
# Point.new
# code_2
# class Tetragon
# end
# class Parallelogram < Tetragon
# end
# class Rectangle < Parallelogram
# end
# class Square < Rectangle
# end
# code_3
# class Point
# def initialize
# p "I am a Point!"
# @x = 3
# @y = 7
# end
# end
# Point.new
# code_3.1
# class Point
# def initialize
# # p "I am a Point!"
# @x = -100
# @y = 99
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# end
# p Point.new.to_s
# code_3.2
# def cube
# p "Hello from method cube"
# 3 * 3 * 3
# end
# p cube
# code_3.3
# def cube val
# # val * val * val
# val ** 3
# end
# p cube 5.2
# code_3.4
# class Point
# def initialize
# # p "I am a Point!"
# @x = 3
# @y = 7
# end
# # def to_s
# # "Point: (#{@x}; #{@y})"
# # end
# end
# p "#{Point.new}"
# code_4
# class Point
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# end
# p Point.new(1,5).to_s
# p Point.new(10,5).to_s
# code_4.1
# class Point
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# def x
# @x
# end
# def y
# @y
# end
# end
# point = Point.new(10,50)
# p point.x
# p point.y
# code_4.2
# class Point
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# def x
# @x
# end
# def y
# @y
# end
# def x= val
# @x = val
# end
# def y= val
# @y = val
# end
# end
# point = Point.new(1,5)
# point.x = 10
# p point.x
# code_4.3
# class Point
# attr_accessor :x, :y
# # attr_reader :x, :y
# # attr_writer :x, :y
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# end
# point = Point.new(1,5)
# point.x= 10
# p point.x
# code_4.4
# class Point
# attr_accessor :x, :y
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# end
# point_1 = Point.new(1,5)
# point_2 = point_1
# point_2.x = 10
# p point_1.x
# p point_2.x
# code_4.5
# ary = [1,2,3]
# def add ary, val
# ary.push val
# end
# add(ary, 7)
# p ary
# code_5
# class Point
# puts self
# attr_accessor :x, :y
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# coordinates = "(#{@x}; #{@y})"
# "Point: #{coordinates}"
# end
# end
# Point.new(1,2).to_s
# code_5.1
# class Point
# attr_accessor :x, :y
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# def + other_point
# # p self
# x = @x + other_point.x
# y = @y + other_point.y
# Point.new(x, y)
# end
# end
# puts Point.new(1,2) + Point.new(-1,3)
# puts Point.new(100,45) + Point.new(50,5)
# puts Point.new(0,0) + Point.new(0,0)
# code_5.2
# class Point
# attr_accessor :x, :y
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# def + other_point
# puts x, y
# x = @x + other_point.x
# y = @y + other_point.y
# Point.new(x, y)
# end
# end
# Point.new(3,-1) + Point.new(3,5)
# code_5.3
# class Point
# attr_accessor :x, :y
# def initialize x, y
# @x = x
# @y = y
# end
# def to_s
# "Point: (#{@x}; #{@y})"
# end
# def + other_point
# x = self.x + other_point.x
# y = self.y + other_point.y
# Point.new(x, y)
# end
# end
# point = Point.new 5, 10
# puts point + Point.new(1, -1)
# puts Point.new(0,0) + Point.new(3,5)
# code_5.4
# class Point < Object
# attr_accessor :x, :y
# def to_s
# super + " Point: (#{@x}; #{@y})"
# end
# def inspect
# "@x=#{@x}; @y=#{@y}"
# end
# def assign_coordinates x, y
# @x = x
# @y = y
# self
# end
# def + other_point
# x = self.x + other_point.x
# y = self.y + other_point.y
# Point.new(x, y)
# end
# end
# point = Point.new.assign_coordinates 5, 2
# puts point
# p point
# code_6
# def dices
# bet = gets.to_i
# sum = rand(1..6) + rand(1..6)
# p sum
# if sum == bet
# puts "You win!"
# else
# puts "You lose."
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment