Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.85 KB | None | 0 0
  1. At=Struct.new(:al, :bl, :a, :b) do
  2.     def initialize
  3.         super
  4.        self.b ||= self.a
  5.     end
  6.      
  7.     def +(other)
  8.     At.new(
  9.       self.al + other.al,
  10.       self.bl + other.bl,
  11.       self.a + other.a,
  12.       self.b + other.b
  13.       )
  14.     end
  15.  
  16.     def -(other)
  17.     At.new(
  18.       self.al + other.al,
  19.       self.bl + other.bl,
  20.       self.a - other.a,
  21.       self.b - other.b
  22.     )
  23.     end
  24.     def *(other)
  25.     At.new(
  26.       self.a * other.al + other.a * self.al,
  27.       self.b * other.bl + other.b * self.bl,
  28.       self.a * other.a,
  29.       self.b * other.b
  30.     )
  31.     end
  32.     def /(other)
  33.     At.new(
  34.       ((self.a * other.bl + other.b * self.al) / (other.b**2)).round(2).inspect,
  35.       ((self.b * other.al + other.a * self.bl) / (other.a**2)).round(2),
  36.       (self.a / other.b).round(2),
  37.       (self.b / other.a).round(2)
  38.     )
  39.     end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement