iAbhimanyuAryan

Ruby exception in class

Feb 18th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.79 KB | None | 0 0
  1. class AuthorizationException < Exception
  2. end
  3.  
  4. class User
  5.   attr_accessor :name, :email, :password, :address, :refferal_id
  6.  
  7.   def tweets
  8.     @tweets = Array.new
  9.   end
  10.  
  11.   def tweets=(tweet)
  12.      @tweets.push
  13.   end
  14.  
  15.   def initialize(name, email, password, details = {})
  16.     self.name = name
  17.     self.email = email
  18.     self.password = password
  19.     self.address = details[:address]
  20.     self.refferal_id = details[:refferal_id]
  21.   end
  22.  
  23.   def get_tweets(list)
  24.     unless list == "Abhimanyu Aryan"
  25.       raise AuthorizationException.new
  26.     end
  27.     @tweets
  28.   end
  29.  
  30.   begin
  31.     tweets = get_tweets("Abhimanyu Aryan")
  32.   rescue AuthorizationException
  33.     puts "Authentication Error"
  34.   end
  35. end
  36.  
  37. user = User.new "Abhimanyu Aryan", "abhimanyuaryan@mail.com", "1234", :address => "stackoverflow"
Add Comment
Please, Sign In to add comment