Ruby, let me ask you a conditional question.

Asked 2 years ago, Updated 2 years ago, 28 views

Let me get to the point briefly.

When writing if statements in Python

For example,

The conditional statement if x in s is if x in s

I don't know how to express this in ruby.

I don't think Ruby supports expressions like xins

Please teach me how to operate the same way.

ruby python

2022-09-22 19:39

2 Answers

x = ["a", "s", "d"]

if x.include? 's'
    puts "hello world"
end


2022-09-22 19:39

http://www.rubydoc.info/stdlib/core/Array:bsearch

I haven't deepened the ruby, but there's a binary search method.


2022-09-22 19:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.