JRuby 9.4.14 on Rails 7.2.2.2 app war deployed on Tomcat 9

Following procedures must use linux or WSL on windows because there are errors related to gem installation if run on windows. I believe we still can do bundle install on windows for Jruby 9.4.0.0 and Rails 7.0.4 on last experiment at 2023. The war file produced can be used on any java 8+ supported platfom (theoretically).

Specify on your rails Gemfile as follow (using the latest warble gem available now) :

Run bundle install.

Run bundle exec warble.

Deploy the war file produced by warble to tomcat 9 (can not use tomcat 10/11).

Use deploy on tomcat 9 manager. Upload war may not work if war file size is too big.

If deployed successfully, check your application on browser.

If we want a executable war then do bundle “exec warble executable war”.

Execute the war as below :

java -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -Dorg.eclipse.jetty.util.log.stderr.ESCAPE=false -jar my_app.war

Thank you !

Rails 7 on Jruby 9.4.0.0

Step to do :

  1. Install Jruby
  2. run jruby -S gem install rails
  3. run jruby -S rails new App
  4. Step 3 will fail miserably related to bindex gem.
  5. Open Gemfile and comment out web-console gem.
  6. Go to your App folder and run jruby -S bundle install
  7. run jruby -S rails server
  8. Browse localhost:3000 to view rails welcome page.

Ruby Lambda Operator

A lambda is a way to define a block and its parameter with special syntax.

greet1 = -> { puts “Hello world.” }

greet2 = lambda { puts “Hello world !” }

greet1.call

greet2.call

greet_with_param = ->(name) { puts “Hello #{name}!” }

greet_with_param.call(“Joni”)

Ruby spaceship operator <=>

The spaceship operator is general comparison operator. The <=> operator compares 2 values and returning -1, 0, or 1 depending on whether the first value is less than, equal, or greater than the second.

Example in irb.

This operator is used on ruby range operation , objects must implement <=> and succ method to perform range operation. Lets test the a numeric value for these methods.

Keep learning ruby on 2021.

Ruby upto for looping

Numeric variable on ruby have upto method that we can use to do looping. Normally looping is done by using while or for syntax. Ruby can do differently.

Example above we loop from 10 to 15. Its simpler right.

Shorthand If and unless in Ruby lang

The basic conditional if in ruby is like any other programming language.

if condition then

[statements to execute if condition is satisfied (true) ]

end

If only a statement needed to executed then we can use shorthand form of if. Statement is at front followed by if and condition.

Ruby also have unless for conditional branching. Difference is statement will be executed if condition not satisfied (false).

Try it yourself at irb ! Bye …

Ruby Programming : Constant

Ruby programming language have constant like other language we know ? Or Ruby dont have ?

Ruby have naming convention related to variable names. If a variable name begin with upper case then its considered constant. Ruby wont stop you to change that constant, it only emit warning like a test case below on irb.

So thats Ruby’s constant.