PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 12, 2022

[FIXED] How can I use method split on ruby module?

 November 12, 2022     macos, memcached, ruby, server, split     No comments   

Issue

Hi everyone's try to use a split method in a module but I can't, the terminal give me this error: undefined method `split' for :"set algo":Symbol (NoMethodError)

class Server
    def initialize(port,ip)
      @server = TCPServer.open(ip,port)
      @connections = Hash.new
      @clients = Hash.new
      @connections[:server] = @server
      @connections[:clients] = @clients
      run
      split
    end

  def run
    loop{
      Thread.start(@server.accept) do | client |
        # for each user connected and accepted by server, it will create a new thread object
        # and which pass the connected client as an instance to the block
        request = client.gets.chomp.to_sym
        dev =  request.split(" ")
        client.puts dev[0]
         #if dev[0] ==  "set"
          #  client.puts "OPERACION VALIDA"
         #else
          #  client.puts "OPERACION INVALIDA "
          #  Thread.kill self
        #end
      end
    }.join
  end



end
 Server.new(3000, "localhost")

Solution

Replace:

request = client.gets.chomp.to_sym

With:

request = client.gets.chomp

Calling to_sym converts the string from gets/chomp to a symbol which doesn't implement split.



Answered By - Stefan
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing