Decision-making operators

Decision-making is also a simple concept, as with any other programming language. Let's have a look at an example:

irb(main):001:0> 1 > 2
=> false  

Let's also consider the case of string data:

irb(main):005:0> "Nipun" == "nipun"
=> false
irb(main):006:0> "Nipun" == "Nipun"
=> true  

Let's consider a simple program with decision-making operators:

def find_match(a) 
if a =~ /Metasploit/ 
return true 
else 
return false 
end 
end 
# Main Starts Here 
a = "1238924983Metasploitduidisdid" 
bool_b=find_match(a) 
print bool_b.to_s 

In the preceding program, we used the word "Metasploit", which sits right in the middle of junk data and is assigned to the a variable. Next, we send this data to the find_match() method, where it matches the /Metasploit/ regex. It returns a true condition if the a variable contains the word "Metasploit", otherwise a false value is assigned to the bool_b variable.

Running the preceding method will produce a valid condition based on the decision-making operator, =~, that matches both the values.

The output of the preceding program will be somewhat similar to the following output when executed in a Windows-based environment:

C:\Ruby23-x64\bin>ruby.exe a.rb
true