Ruby rails - net-ldap search not working

I am trying to search ldap. This is doing successful authentication, I
verified using a correct and incorrect password. Ldap connection is
successful. Then when I make a search query it can
not read attributes from LDAP (AD). What is wrong here?

#!/usr/bin/env ruby
require “net-ldap”
$username = String.new

class ActiveDirectoryUser
SERVER = ‘10.10.10.10’
PORT = 389
BASE = ‘DC=mydomain,DC=com’
DOMAIN = ‘mydomain.com

def self.authenticate(login, pass)
conn = Net::LDAP.new :host => SERVER,
:port => PORT,
:base => BASE,
:auth => { :username => “#{login}@#{DOMAIN}”,
:password => pass,
:method => :simple }
if conn.bind
conn.search(
:base => BASE, :filter => Net::LDAP::Filter.eq(
“sAMAccountName”, login ),
:attributes => %w[ givenName ], :return_result => true) do
|entry|
puts “givenName: #{entry.givenName}”
$username = entry.givenName
end
return true

else
  return false
end

rescue Net::LDAP::LdapError => e
return false
end
end

if ActiveDirectoryUser.authenticate(‘myusername’, ‘mypassword’)
puts "Authentication Successful! The user is "+$username

I get this,but blank username

else
puts “Authentication FAILED!”
end


./ad.rb

Authentication Successful! The user is