Comparing multiple values in an if statement - Ruby [closed] - ruby

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Can you compare multiple values in a single if statement in Ruby? If so, how? I know in other languages, you would just use a double ampersand (&&), but I have never seen any example or documentation about it, even in the official ruby documentation! Thanks for all the help in advance.

Yes, you can use the && operator
if a == 1 && b == 2
# do things
end

It IS in the documentation.
http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#UG

Related

How do I combine two attributes using uniq? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Currently I am doing the following and was wondering if there was a way of merging this?
merged = list_with_objects_that_have_url_and_name_attributes
merged = merged.uniq{|ex| ex.url }
merged = merged.uniq{|ex| ex.name }
I'd like something like:
merged.uniq{|ex| ex.name || ex.url}
Not quite what you asked for, but it's compact:
merged.uniq!(&:url).uniq!(&:name)

Filtering List based on a nested list using LINQ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Let's say we have a List of Projects and this list contains another list of Users.
How can I construct a LINQ query that let's say get me all the projects of a specific user based on his UserID?
Thanks.
Lets try something like this:
Projects.Where(pr => pr.Users.Any(us => us.ID == uid) )
I suggest to You read LINQ tutorial or here as well

Regular expression to find unknown acronyms [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I need a regular expression that will pick out lines with ALL CAPS or unknown acronyms.
ie: something like
/[A-Z]{2,}/
combined with
/(?!USA|UK|TLA)/
You mean something like this?
\b(?!(?:USA|UK|TLA)\b)[A-Z]{2,}\b
See it here on Rubular
\b is a word boundary to ensure that it will find complete words.

What do these Fortran (90) statements do? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have run into the follow code and I do not understand it. What does it do?
A(*)
do n=(k,k-1,j+1-k)
A(*) looks like (part of) the declaration of an 'assumed-size array'; the typical use of this would be in the declaration of a dummy argument to a procedure. Distinguish carefully between assumed-size and 'automatic' arrays. Assumed-size arrays are deprecated in modern Fortran but common in FORTRAN77 and earlier variations.
do n=(k,k-1,j+1-k) looks like a syntactically-incorrect loop statement. The correct form would be do n=k,k-1,j+1-k which loops over the range [k,k-1] in strides of size j+1-k.

How to modify string using RegEx? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How do I transform the string from 'updown' to 'Up/Down' using RegEx?
If you already know the input and output string then there's no use case for regular expressions. Regular expressions are for matching a grammar, which is a set of strings, rather than a single string.
Are you looking for something more general? Perhaps your question is about how to split up the words up and down, or how to capitalize the letters?
string = "updown"
string.gsub!("up", "Up!")
string.gsub!("down", "Down")
string = "Up!Down"

Resources