Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
codeDude :archlinux: :neovim:
codeDude :archlinux: :neovim:
@codeDude@floss.social  ·  activity timestamp 2 weeks ago

#ruby can change this
```ruby

def response
command = @client.gets&.strip

case command
when "pause" then @countdown.pause
when "resume" then @countdown.resume
when "stop" then @countdown.stop
when "status" then @countdown.status
else raise ArgumentError "ERR: unknown command"
end
end
```
by this
```ruby

def response
command = @client.gets&.strip
@countdown.send command
end
```
and this is awesome

  • Copy link
  • Flag this post
  • Block
Esparta :ruby:
Esparta :ruby:
@esparta@ruby.social replied  ·  activity timestamp 2 weeks ago

@codeDude using `send` or even `public_send` looks like a good idea until it is not, a sanitation/restriction of which method can be called should be preffered. The reasoning behind this, and specially if that `gets` is an external input, is security: a method can be called and that might be not exactly what you meant, for example, if this is an ActiveRecord object, then the ` #destroy` method might be called, effectively deleting that particular entry in the database.

  • Copy link
  • Flag this comment
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.2-alpha.23 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct