By ear. Its how I taught myself how to play. I listen to something I like and try to play it. Try and try until I get it right. It helped with learning where each sound is on the fingerboard which makes learning songs even easier. When I have trouble learning how to play a song mainly because I can't figure out certain notes in a harmony, I slow down the song with a computer program to have better clarity of the notes. Tabs I used to look at for learning difficult unclear solos but I find that most of the songs I look at tabs for are played inconveniently due to the way they are tabbed. So I've stayws away from tabs unless its something tabbed by the artist of the song.
When I compose a song (saying compose since I don't actually write anything), I'm often playing random things on the guitar and if I manage to like what I'm playing, I play it enough times and to be sure I won't forget I type it into Guitar Pro. Some of the songs I compose are pieced together that way. Sometimes I kind of know how I want a song to sound like, so it just flows out.