Ruby-net-ldap paged search control


Could anyone help me on how to use the ruby-net-ldap paged search
I have read in forums that Net::LDAP library supports paged results
My problem is I don’t know how to embed it in my code.

I need to search users from ldap and paginate the results return by the

Here is the sample code.

ldap = {:host => LDAP_SERVER_IP_ADDRESS,
:port => LDAP_SERVER_PORT } )
#call LDAP authentication
ldap.auth( “#{LDAP_USERNAME}”,"#{LDAP_PWD}" )

user_array = []
user_hash = {}
treebase = “sample treebase”
filter = “myfilter”
attrs = [“sample attributes”]

#bind LDAP authentication
if ldap.bind>treebase, :filter=>filter,:attributes=>attrs) do
#I process the entry here to store in hash
user_hash = {
:name => entry[:cn],
user_array << user_hash

return user_array

Please help me on where should do it. Can you please give me code
snippet so that I can embed it in my code.

Many Thanks.