HacketyLib

While this is informal documentation for the libraries which come with Hackety Hack, the quality parts will be added to the manual which comes with HH. Please help to flesh out anything confusing or to add anything missing.

For methods which come with Ruby, see the RubyLib page.

Built-in Methods

These methods can be used anywhere throughout Hackety Hack programs.

ask( message )

Pops up a window and asks a question. For example, you may want to ask someone their name.

 #!ruby
 name = ask("Please, enter your name:")

When the above script is run, the person at the computer will see a window with a blank box for entering their name. The name will then be saved in the name variable.

ask_open_file()

Pops up an "Open file..." window. It's the standard window which show all of your folders and lets you select a file to open. Hands you back the name of the file.

 #!ruby
 filename = ask_open_file
 puts File.read(filename)

ask_save_file()

Pops up a "Save file..." window, similiar to ask_open_file, described above.

 #!ruby
 save_as = ask_save_file

exit()

Stops your program. Call this anytime you want to suddenly call it quits.

print( message, message, ... )

Write something on the Hackety Hack program page. Every program has a hidden page which can be written on. When the program is done, this page appears. You can use this page to show a report of everything the program did. Or you can build a page with links to other programs or files.

 #!ruby
 print "The program is done.  Now everyone can go home."

puts( message, message, ... )

A variation on print. The print method writes messages on one long line. The puts method, however, will write each of its messages on a separate line.

 #!ruby
 puts "Hi.", "Hello.", "Anyone there?"

The code above will print each message on its own line.

 Hi.
 Hello.
 Anyone there?

p( obj, obj, ... )

The p method helps you see what kinds of objects you're dealing with. If you have an object in the stuff variable, you can use p to find out what's inside.

 #!ruby
 stuff = Web.fetch("http://feeds.feedburner.com/boingboing/iBag")
 p stuff

In the above example, the Web.fetch method is use to get a feed for the Boing Boing blog.

 (Web::Feed "Boing Boing")

Sure enough, the stuff variable has a feed in it!

say( message )

When a program is running, a little barbershop pole spins with a message that reads "Running...". If your program is running for awhile, you may want to change that message. Maybe you'll want to let the person at the computer know that you're 50% done.

 #!ruby
 say("Okay, I'm 50% done.")

Once your program is finished, the message and the barbershop pole will disappear.

The Table library

Tables are for storing a list of things which are similiar. For instance: a blog.

Blog entries are similiar: they each have a title and a main area. You could store a series of blog entries in a single table.

Also see Web.popup(name), which automatically creates tables which are attached to popups.

only( a Number )

Gets a specific item from the Table using its ID.

 #!ruby
 entry = Table("Blog").only(6)
 puts entry["Title"]

recent( a Number )

Gets the most recent items from the Table.

 #!ruby
 entries = Table("Blog").recent(10)

This will load the ten most recent entries from the Blog table.

The Web library

The Web library contains methods for downloading files and grabbing information from the Web.

Web.download( url: a String , save_as: a String )

If you'd like to save a file from the Web to your computer, use Web.download with two arguments. The first is a URL to the file on the web. The second argument is a name for the file on your computer.

 #!ruby
 Web.download("http://example.org/songs/Y-Fford-Oren.mp3", "y-fford-oren.mp3")

Web.fetch( url: a String )

If you'd like to grab a web page and store it in a variable, use Web.fetch.

 #!ruby
 google = Web.fetch("http://google.com/search")

Should Web.fetch encounter an RSS or XML feed, you will be handed back a Web::Feed object containing the news items.

Web.page { ... }

Since Hackety Hack is built on top of a browser, you can build web pages on the hidden program page. It uses a language like HTML but with {}'s instead of <>'s.Need to come up with a way to explain all this...

 #!ruby
 Web.page {
   h1 'My links'
   ul {
     li { a 'Google', :href => 'http://google.com' }
     li { a 'Hackety Hack', :href => 'http://code.whytheluckystiff.net/hacketyhack/' }  
   }
 }

Web.popup { ... }

Opens an in-browser popup. Inside the block, create the popup contents just as described in Web.page above.

 #!ruby
 Web.popup {
   h1 'Are you sure?'
   buttons { cancel; save }
 }

Web.popup( name: a String ) { ... }

This is a variation on the in-browser popup above. You still create a popup from inside the block.

The difference is the string passed into the method. The string will be used to attach the popup to a Table.

 #!ruby
 Web.popup("Blog") do
   title "Add a Blog Entry"
   editline "Title"
   editbox
   buttons { cancel; save }
 end

In this example, the popup stores its information in the Blog table. Two things will be stored in the table: the editline called "Title" and the editbox, which will be called "Editbox". If the table doesn't exist, it'll be created from the popup.

Also see the Table help section for more on working with tables.